Align income tax calculation to Australian income tax

This commit is contained in:
RunasSudo 2023-01-03 00:04:23 +11:00
parent 9d5873376f
commit f78f17c0cb
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
5 changed files with 82 additions and 36 deletions

View File

@ -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': []
}

View File

@ -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)

View File

@ -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
)

View File

@ -26,7 +26,7 @@
</head>
<body>
{% block body %}
<nav class="navbar navbar-expand-sm navbar-light bg-light">
<nav class="navbar navbar-expand-sm navbar-light bg-light d-print-none">
<div class="container">
<a class="navbar-brand" href="/">DrCr</a>
<div class="collapse navbar-collapse">
@ -42,7 +42,7 @@
{% block content %}{% endblock %}
{% if config['DEBUG'] %}
<footer class="border-top pt-4 mt-4">
<footer class="border-top pt-4 mt-4 d-print-none">
<p class="text-muted">Queries executed in {{ dbtime() }} msec. Page generated in __EXECUTION_TIME__ msec.</p>
</footer>
{% endif %}

View File

@ -18,27 +18,28 @@
{% extends 'base.html' %}
{% block title %}Tax summary{% endblock %}
{% macro fmtbal(amount, mul=1) %}
{% macro fmtbal(amount, rnd=1, mul=1) %}
{# FIXME: Honour AMOUNT_DPS #}
{% if amount.quantity * mul >= 0 %}
{{ '{:,.2f}'.format(amount.quantity|abs / 100) }}&nbsp;
{{ '{:,.2f}'.format((amount.quantity|abs / rnd)|round(0, 'floor') * rnd / 100) }}&nbsp;
{% else %}
({{ '{:,.2f}'.format(amount.quantity|abs / 100) }})
({{ '{:,.2f}'.format((amount.quantity|abs / rnd)|round(0, 'floor') * rnd / 100) }})
{% endif %}
{% endmacro %}
{% macro acctrow(name, mul=1) %}
{% macro acctrow(name, rnd=1, mul=1) %}
<tr>
<td>{{ name }}</td>
<td class="text-end">{{ fmtbal(accounts[name], mul) }}</td>
<td class="text-end">{{ fmtbal(accounts[name], rnd, mul) }}</td>
</tr>
{% set _ = running_total.__setattr__('quantity', running_total.quantity + accounts[name].quantity) %}
{% set rnd_qty = (accounts[name].quantity|abs / rnd)|round(0, 'floor') * rnd * accounts[name].quantity/(accounts[name].quantity|abs) %}
{% set _ = running_total.__setattr__('quantity', running_total.quantity + rnd_qty) %}
{% endmacro %}
{% block content %}
<h1 class="h2 mt-4">Tax summary</h1>
<table class="table table-borderless">
<table class="table table-borderless table-sm">
<thead>
<tr style="border-width:0 0 1px 0">
<th></th>
@ -47,27 +48,51 @@
</thead>
<tbody>
<tr>
<th colspan="2">Assessable income</th>
<th colspan="2">Salary and wages (1)</th>
</tr>
{% set _ = running_total.__setattr__('quantity', 0) %}
{% for account in TAX_MAPPING['Assessable income'] if account in accounts %}
{{ acctrow(account, -1) }}
{% for account in TAX_MAPPING['Salary and wages'] if account in accounts %}
{{ acctrow(account, 100, -1) }}
{% endfor %}
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
<th colspan="2">Government allowances (5)</th>
</tr>
{% for account in TAX_MAPPING['Government allowances'] if account in accounts %}
{{ acctrow(account, 100, -1) }}
{% endfor %}
<tr><td colspan="2">&nbsp;</td></tr>
<tr style="border-width:1px 0">
<th>Total assessable income</th>
<th class="text-end">{{ fmtbal(running_total, -1) }}</th>
<th class="text-end">{{ fmtbal(running_total, 1, -1) }}</th>
</tr>
{% set taxable_income = running_total.quantity %}
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
<th colspan="2">Deductions</th>
<th colspan="2">Work-related self-education expenses (D4)</th>
</tr>
{% set _ = running_total.__setattr__('quantity', 0) %}
{% for account in TAX_MAPPING['Deductions'] if account in accounts %}
{{ acctrow(account) }}
{% for account in TAX_MAPPING['Work-related self-education expenses'] if account in accounts %}
{{ acctrow(account, 100) }}
{% endfor %}
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
<th colspan="2">Other work-related expenses (D5)</th>
</tr>
{% for account in TAX_MAPPING['Other work-related expenses'] if account in accounts %}
{{ acctrow(account, 100) }}
{% endfor %}
<tr><td colspan="2">&nbsp;</td></tr>
<tr style="border-width:1px 0">
<th>Total deductions</th>
<th class="text-end">{{ fmtbal(running_total) }}</th>
@ -76,14 +101,19 @@
<tr><td colspan="2">&nbsp;</td></tr>
{% set _ = running_total.__setattr__('quantity', taxable_income) %}
<tr style="border-width:1px 0">
<th>Taxable income</th>
<th class="text-end">{{ fmtbal(running_total, -1) }}</th>
{% set _ = running_total.__setattr__('quantity', taxable_income) %}
<th class="text-end">{{ fmtbal(running_total, 1, -1) }}</th>
</tr>
<tr>
<td>Tax on taxable income</td>
<td class="text-end">{{ fmtbal(calculate_tax(running_total)) }}</td>
<td>Income tax</td>
<td class="text-end">{{ fmtbal(base_income_tax(running_total)) }}</td>
</tr>
<tr>
<td>Medicare levy</td>
{% set _ = running_total.__setattr__('quantity', taxable_income * 0.02) %}
<td class="text-end">{{ fmtbal(running_total, 1, -1) }}</td>
</tr>
</tbody>
</table>