Align income tax calculation to Australian income tax
This commit is contained in:
parent
9d5873376f
commit
f78f17c0cb
@ -22,6 +22,8 @@ INCOME_STATEMENT_MAPPING = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TAX_MAPPING = {
|
TAX_MAPPING = {
|
||||||
'Assessable income': [],
|
'Government allowances': [],
|
||||||
'Deductions': []
|
'Other work-related expenses': [],
|
||||||
|
'Salary and wages': [],
|
||||||
|
'Work-related self-education expenses': []
|
||||||
}
|
}
|
||||||
|
@ -24,22 +24,36 @@ def taxable_income():
|
|||||||
balancer.apply_transactions(Transaction.query.all())
|
balancer.apply_transactions(Transaction.query.all())
|
||||||
|
|
||||||
result = Amount(0, '$')
|
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
|
return result
|
||||||
|
|
||||||
def calculate_tax(taxable_income):
|
def base_income_tax(taxable_income):
|
||||||
taxable_income = -taxable_income.as_cost().quantity
|
income = -taxable_income.as_cost().quantity
|
||||||
|
|
||||||
if taxable_income <= 1820000:
|
if income <= 1820000:
|
||||||
return Amount(0, '$')
|
return Amount(0, '$')
|
||||||
if taxable_income <= 4500000:
|
if income <= 4500000:
|
||||||
return Amount(int((taxable_income - 1820000) * 0.19), '$')
|
return Amount(int((income - 1820000) * 0.19), '$')
|
||||||
if taxable_income <= 12000000:
|
if income <= 12000000:
|
||||||
return Amount(int(509200 + (taxable_income - 4500000) * 0.325), '$')
|
return Amount(int(509200 + (income - 4500000) * 0.325), '$')
|
||||||
if taxable_income <= 18000000:
|
if income <= 18000000:
|
||||||
return Amount(int(2946700 + (taxable_income - 12000000) * 0.37), '$')
|
return Amount(int(2946700 + (income - 12000000) * 0.37), '$')
|
||||||
return Amount(int(5166700 + (taxable_income - 18000000) * 0.45), '$')
|
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):
|
def tax_transaction(taxable_income):
|
||||||
tax = calculate_tax(taxable_income)
|
tax = calculate_tax(taxable_income)
|
||||||
|
@ -19,7 +19,7 @@ from flask import render_template
|
|||||||
from ..config import TAX_MAPPING
|
from ..config import TAX_MAPPING
|
||||||
from ..models import Amount, TrialBalancer
|
from ..models import Amount, TrialBalancer
|
||||||
from ..webapp import all_transactions, app
|
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')
|
@app.route('/tax/summary')
|
||||||
def tax_summary():
|
def tax_summary():
|
||||||
@ -30,7 +30,7 @@ def tax_summary():
|
|||||||
return render_template(
|
return render_template(
|
||||||
'tax/summary.html',
|
'tax/summary.html',
|
||||||
accounts=balancer.accounts,
|
accounts=balancer.accounts,
|
||||||
calculate_tax=calculate_tax,
|
base_income_tax=base_income_tax, calculate_tax=calculate_tax,
|
||||||
running_total=Amount(0, '$'),
|
running_total=Amount(0, '$'),
|
||||||
TAX_MAPPING=TAX_MAPPING
|
TAX_MAPPING=TAX_MAPPING
|
||||||
)
|
)
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% block 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">
|
<div class="container">
|
||||||
<a class="navbar-brand" href="/">DrCr</a>
|
<a class="navbar-brand" href="/">DrCr</a>
|
||||||
<div class="collapse navbar-collapse">
|
<div class="collapse navbar-collapse">
|
||||||
@ -42,7 +42,7 @@
|
|||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
|
|
||||||
{% if config['DEBUG'] %}
|
{% 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>
|
<p class="text-muted">Queries executed in {{ dbtime() }} msec. Page generated in __EXECUTION_TIME__ msec.</p>
|
||||||
</footer>
|
</footer>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -18,27 +18,28 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
{% block title %}Tax summary{% endblock %}
|
{% block title %}Tax summary{% endblock %}
|
||||||
|
|
||||||
{% macro fmtbal(amount, mul=1) %}
|
{% macro fmtbal(amount, rnd=1, mul=1) %}
|
||||||
{# FIXME: Honour AMOUNT_DPS #}
|
{# FIXME: Honour AMOUNT_DPS #}
|
||||||
{% if amount.quantity * mul >= 0 %}
|
{% if amount.quantity * mul >= 0 %}
|
||||||
{{ '{:,.2f}'.format(amount.quantity|abs / 100) }}
|
{{ '{:,.2f}'.format((amount.quantity|abs / rnd)|round(0, 'floor') * rnd / 100) }}
|
||||||
{% else %}
|
{% else %}
|
||||||
({{ '{:,.2f}'.format(amount.quantity|abs / 100) }})
|
({{ '{:,.2f}'.format((amount.quantity|abs / rnd)|round(0, 'floor') * rnd / 100) }})
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro acctrow(name, mul=1) %}
|
{% macro acctrow(name, rnd=1, mul=1) %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ name }}</td>
|
<td>{{ name }}</td>
|
||||||
<td class="text-end">{{ fmtbal(accounts[name], mul) }}</td>
|
<td class="text-end">{{ fmtbal(accounts[name], rnd, mul) }}</td>
|
||||||
</tr>
|
</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 %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1 class="h2 mt-4">Tax summary</h1>
|
<h1 class="h2 mt-4">Tax summary</h1>
|
||||||
|
|
||||||
<table class="table table-borderless">
|
<table class="table table-borderless table-sm">
|
||||||
<thead>
|
<thead>
|
||||||
<tr style="border-width:0 0 1px 0">
|
<tr style="border-width:0 0 1px 0">
|
||||||
<th></th>
|
<th></th>
|
||||||
@ -47,27 +48,51 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="2">Assessable income</th>
|
<th colspan="2">Salary and wages (1)</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% set _ = running_total.__setattr__('quantity', 0) %}
|
{% set _ = running_total.__setattr__('quantity', 0) %}
|
||||||
{% for account in TAX_MAPPING['Assessable income'] if account in accounts %}
|
{% for account in TAX_MAPPING['Salary and wages'] if account in accounts %}
|
||||||
{{ acctrow(account, -1) }}
|
{{ acctrow(account, 100, -1) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
<tr><td colspan="2"> </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"> </td></tr>
|
||||||
|
|
||||||
<tr style="border-width:1px 0">
|
<tr style="border-width:1px 0">
|
||||||
<th>Total assessable income</th>
|
<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>
|
</tr>
|
||||||
{% set taxable_income = running_total.quantity %}
|
{% set taxable_income = running_total.quantity %}
|
||||||
|
|
||||||
<tr><td colspan="2"> </td></tr>
|
<tr><td colspan="2"> </td></tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="2">Deductions</th>
|
<th colspan="2">Work-related self-education expenses (D4)</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% set _ = running_total.__setattr__('quantity', 0) %}
|
{% set _ = running_total.__setattr__('quantity', 0) %}
|
||||||
{% for account in TAX_MAPPING['Deductions'] if account in accounts %}
|
{% for account in TAX_MAPPING['Work-related self-education expenses'] if account in accounts %}
|
||||||
{{ acctrow(account) }}
|
{{ acctrow(account, 100) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
<tr><td colspan="2"> </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"> </td></tr>
|
||||||
|
|
||||||
<tr style="border-width:1px 0">
|
<tr style="border-width:1px 0">
|
||||||
<th>Total deductions</th>
|
<th>Total deductions</th>
|
||||||
<th class="text-end">{{ fmtbal(running_total) }}</th>
|
<th class="text-end">{{ fmtbal(running_total) }}</th>
|
||||||
@ -76,14 +101,19 @@
|
|||||||
|
|
||||||
<tr><td colspan="2"> </td></tr>
|
<tr><td colspan="2"> </td></tr>
|
||||||
|
|
||||||
{% set _ = running_total.__setattr__('quantity', taxable_income) %}
|
|
||||||
<tr style="border-width:1px 0">
|
<tr style="border-width:1px 0">
|
||||||
<th>Taxable income</th>
|
<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>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Tax on taxable income</td>
|
<td>Income tax</td>
|
||||||
<td class="text-end">{{ fmtbal(calculate_tax(running_total)) }}</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>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
Loading…
Reference in New Issue
Block a user