From f78f17c0cba3f494888135f3e9aebd1e9acae1fe Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Tue, 3 Jan 2023 00:04:23 +1100 Subject: [PATCH] Align income tax calculation to Australian income tax --- drcr/config.py.example | 6 ++- drcr/tax/aus_tax.py | 38 +++++++++++++------ drcr/tax/views.py | 4 +- drcr/templates/base.html | 4 +- drcr/templates/tax/summary.html | 66 ++++++++++++++++++++++++--------- 5 files changed, 82 insertions(+), 36 deletions(-) diff --git a/drcr/config.py.example b/drcr/config.py.example index 9fa0f3f..9a104e6 100644 --- a/drcr/config.py.example +++ b/drcr/config.py.example @@ -22,6 +22,8 @@ INCOME_STATEMENT_MAPPING = { } TAX_MAPPING = { - 'Assessable income': [], - 'Deductions': [] + 'Government allowances': [], + 'Other work-related expenses': [], + 'Salary and wages': [], + 'Work-related self-education expenses': [] } diff --git a/drcr/tax/aus_tax.py b/drcr/tax/aus_tax.py index 3c5eff0..ec73b7f 100644 --- a/drcr/tax/aus_tax.py +++ b/drcr/tax/aus_tax.py @@ -24,22 +24,36 @@ def taxable_income(): balancer.apply_transactions(Transaction.query.all()) result = Amount(0, '$') - for account in TAX_MAPPING['Assessable income']: - result.quantity += balancer.accounts[account].quantity + + for account in TAX_MAPPING['Salary and wages']: + result.quantity += int(balancer.accounts[account].quantity / 100) * 100 + for account in TAX_MAPPING['Government allowances']: + result.quantity += int(balancer.accounts[account].quantity / 100) * 100 + for account in TAX_MAPPING['Work-related self-education expenses']: + result.quantity += int(balancer.accounts[account].quantity / 100) * 100 + for account in TAX_MAPPING['Other work-related expenses']: + result.quantity += int(balancer.accounts[account].quantity / 100) * 100 + return result -def calculate_tax(taxable_income): - taxable_income = -taxable_income.as_cost().quantity +def base_income_tax(taxable_income): + income = -taxable_income.as_cost().quantity - if taxable_income <= 1820000: + if income <= 1820000: return Amount(0, '$') - if taxable_income <= 4500000: - return Amount(int((taxable_income - 1820000) * 0.19), '$') - if taxable_income <= 12000000: - return Amount(int(509200 + (taxable_income - 4500000) * 0.325), '$') - if taxable_income <= 18000000: - return Amount(int(2946700 + (taxable_income - 12000000) * 0.37), '$') - return Amount(int(5166700 + (taxable_income - 18000000) * 0.45), '$') + if income <= 4500000: + return Amount(int((income - 1820000) * 0.19), '$') + if income <= 12000000: + return Amount(int(509200 + (income - 4500000) * 0.325), '$') + if income <= 18000000: + return Amount(int(2946700 + (income - 12000000) * 0.37), '$') + return Amount(int(5166700 + (income - 18000000) * 0.45), '$') + +def calculate_tax(taxable_income): + income = -taxable_income.as_cost().quantity + medicare_levy = int(income * 0.02) + + return Amount(base_income_tax(taxable_income).quantity + medicare_levy, '$') def tax_transaction(taxable_income): tax = calculate_tax(taxable_income) diff --git a/drcr/tax/views.py b/drcr/tax/views.py index ee72ca7..90ad061 100644 --- a/drcr/tax/views.py +++ b/drcr/tax/views.py @@ -19,7 +19,7 @@ from flask import render_template from ..config import TAX_MAPPING from ..models import Amount, TrialBalancer from ..webapp import all_transactions, app -from .aus_tax import calculate_tax +from .aus_tax import base_income_tax, calculate_tax @app.route('/tax/summary') def tax_summary(): @@ -30,7 +30,7 @@ def tax_summary(): return render_template( 'tax/summary.html', accounts=balancer.accounts, - calculate_tax=calculate_tax, + base_income_tax=base_income_tax, calculate_tax=calculate_tax, running_total=Amount(0, '$'), TAX_MAPPING=TAX_MAPPING ) diff --git a/drcr/templates/base.html b/drcr/templates/base.html index 541be5b..06cb3d3 100644 --- a/drcr/templates/base.html +++ b/drcr/templates/base.html @@ -26,7 +26,7 @@ {% block body %} -