DrCr/austax/__init__.py

59 lines
2.1 KiB
Python

# DrCr: Web-based double-entry bookkeeping framework
# Copyright (C) 2022–2023 Lee Yingtong Li (RunasSudo)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from flask import render_template
from drcr.models import Posting, Transaction
import drcr.plugins
from drcr.webapp import app
from .reports import tax_summary_report
from datetime import datetime
def plugin_init():
drcr.plugins.advanced_reports.append(('/tax/summary', 'Tax summary'))
drcr.plugins.account_kinds.append(('austax.income1', 'Salary or wages (1)'))
drcr.plugins.account_kinds.append(('austax.income5', 'Australian Government allowances and payments (5)'))
drcr.plugins.account_kinds.append(('austax.d4', 'Work-related self-education expenses (D4)'))
drcr.plugins.account_kinds.append(('austax.d5', 'Other work-related expenses (D5)'))
drcr.plugins.transaction_providers.append(make_tax_transactions)
@app.route('/tax/summary')
def tax_summary():
report = tax_summary_report()
return render_template('report.html', report=report)
def make_tax_transactions():
report = tax_summary_report()
tax_amount = report.by_id('total_tax').amount
# Get EOFY date
dt = datetime.now().replace(month=6, day=30)
if dt < datetime.now():
dt = dt.replace(year=dt.year + 1)
return [Transaction(
dt=dt,
description='Estimated tax payable',
postings=[
Posting(account='Income Tax', quantity=tax_amount.quantity, commodity='$'),
Posting(account='Income Tax Control', quantity=-tax_amount.quantity, commodity='$')
]
)]