austax: Add recording of PAYG withheld amounts

This commit is contained in:
RunasSudo 2023-01-05 18:36:01 +11:00
parent 8777ddd0ef
commit 0caedab327
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 47 additions and 6 deletions

View File

@ -16,7 +16,8 @@
from flask import render_template from flask import render_template
from drcr.models import Posting, Transaction from drcr.models import AccountConfiguration, Posting, Transaction, TrialBalancer
from drcr.database import db
import drcr.plugins import drcr.plugins
from drcr.webapp import app from drcr.webapp import app
@ -31,6 +32,7 @@ def plugin_init():
drcr.plugins.account_kinds.append(('austax.income5', 'Australian Government allowances and payments (5)')) 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.d4', 'Work-related self-education expenses (D4)'))
drcr.plugins.account_kinds.append(('austax.d5', 'Other work-related expenses (D5)')) drcr.plugins.account_kinds.append(('austax.d5', 'Other work-related expenses (D5)'))
drcr.plugins.account_kinds.append(('austax.paygw', 'PAYG withheld amounts'))
drcr.plugins.transaction_providers.append(make_tax_transactions) drcr.plugins.transaction_providers.append(make_tax_transactions)
@ -48,11 +50,37 @@ def make_tax_transactions():
if dt < datetime.now(): if dt < datetime.now():
dt = dt.replace(year=dt.year + 1) dt = dt.replace(year=dt.year + 1)
return [Transaction( # Estimated tax payable
transactions = [Transaction(
dt=dt, dt=dt,
description='Estimated tax payable', description='Estimated income tax',
postings=[ postings=[
Posting(account='Income Tax', quantity=tax_amount.quantity, commodity='$'), Posting(account='Income Tax', quantity=tax_amount.quantity, commodity='$'),
Posting(account='Income Tax Control', quantity=-tax_amount.quantity, commodity='$') Posting(account='Income Tax Control', quantity=-tax_amount.quantity, commodity='$')
] ]
)] )]
# Get trial balance
balancer = TrialBalancer()
balancer.apply_transactions(db.session.scalars(db.select(Transaction).options(db.selectinload(Transaction.postings))).all())
accounts = dict(sorted(balancer.accounts.items()))
# Get account configurations
account_configurations = AccountConfiguration.get_all_kinds()
# PAYG withholding
for account_name, kinds in account_configurations.items():
if 'austax.paygw' in kinds:
if accounts[account_name].quantity != 0:
# Transfer balance to Income Tax Control
transactions.append(Transaction(
dt=dt,
description='PAYG withheld amounts',
postings=[
Posting(account='Income Tax Control', quantity=accounts[account_name].quantity, commodity='$'),
Posting(account=account_name, quantity=-accounts[account_name].quantity, commodity='$')
]
))
return transactions

View File

@ -89,24 +89,37 @@ def tax_summary_report():
), ),
Spacer(), Spacer(),
Calculated( Calculated(
'Taxable income', 'Net taxable income',
lambda r: r.by_id('assessable').amount - r.by_id('deductions').amount, lambda r: r.by_id('assessable').amount - r.by_id('deductions').amount,
id='taxable', id='taxable',
heading=True, heading=True,
bordered=True bordered=True
), ),
Spacer(),
Section( Section(
entries=[ entries=[
Calculated( Calculated(
'Income tax', 'Base income tax',
lambda _: base_income_tax(report.by_id('taxable').amount) lambda _: base_income_tax(report.by_id('taxable').amount)
), ),
Calculated( Calculated(
'Medicare levy', 'Medicare levy',
lambda _: medicare_levy(report.by_id('taxable').amount) lambda _: medicare_levy(report.by_id('taxable').amount)
), ),
Subtotal(id='total_tax', visible=False) Subtotal('Total income tax', id='total_tax', bordered=True)
] ]
),
Spacer(),
Section(
title='PAYG withheld amounts',
entries=entries_for_kind(account_configurations, accounts, 'austax.paygw') + [Subtotal('Total withheld amounts', id='paygw')]
),
Spacer(),
Calculated(
'Income tax payable (refundable)',
lambda _: report.by_id('total_tax').amount - report.by_id('paygw').amount,
heading=True,
bordered=True
) )
] ]
) )