DrCr/drcr/tax/aus_tax.py

60 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 ..config import TAX_MAPPING
from ..models import Amount, Posting, Transaction, TrialBalancer
from datetime import datetime
def taxable_income():
balancer = TrialBalancer()
balancer.apply_transactions(Transaction.query.all())
result = Amount(0, '$')
for account in TAX_MAPPING['Assessable income']:
result.quantity += balancer.accounts[account].quantity
return result
def calculate_tax(taxable_income):
taxable_income = -taxable_income.as_cost().quantity
if taxable_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), '$')
def tax_transaction(taxable_income):
tax = calculate_tax(taxable_income)
# 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.quantity, commodity='$'),
Posting(account='Income Tax Control', quantity=-tax.quantity, commodity='$')
]
)