2023-01-04 18:03:08 +11:00
|
|
|
# DrCr: Web-based double-entry bookkeeping framework
|
2024-08-16 22:40:10 +10:00
|
|
|
# Copyright (C) 2022–2024 Lee Yingtong Li (RunasSudo)
|
2023-01-04 18:03:08 +11:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
2023-01-07 19:01:05 +11:00
|
|
|
from flask import render_template, url_for
|
2023-01-04 18:03:08 +11:00
|
|
|
|
2024-11-09 18:14:25 +11:00
|
|
|
from drcr.models import AccountConfiguration, Posting, Transaction, TrialBalancer, reporting_commodity
|
2023-01-05 18:36:01 +11:00
|
|
|
from drcr.database import db
|
2024-11-11 16:28:59 +11:00
|
|
|
from drcr.webapp import eofy_date, sofy_date
|
2023-01-04 18:03:08 +11:00
|
|
|
import drcr.plugins
|
|
|
|
|
2024-11-09 18:14:25 +11:00
|
|
|
from . import views # Load routes
|
2023-09-18 21:29:58 +10:00
|
|
|
from .reports import tax_summary_report
|
2024-11-09 18:14:25 +11:00
|
|
|
from .util import assert_aud
|
2023-01-04 18:03:08 +11:00
|
|
|
|
|
|
|
def plugin_init():
|
2023-01-07 19:01:05 +11:00
|
|
|
drcr.plugins.data_sources.append(('cgt_adjustments', 'CGT adjustments'))
|
|
|
|
drcr.plugins.advanced_reports.append(('cgt_assets', 'CGT assets'))
|
|
|
|
drcr.plugins.advanced_reports.append(('tax_summary', 'Tax summary'))
|
2023-01-04 18:03:08 +11:00
|
|
|
|
|
|
|
drcr.plugins.account_kinds.append(('austax.income1', 'Salary or wages (1)'))
|
|
|
|
drcr.plugins.account_kinds.append(('austax.income5', 'Australian Government allowances and payments (5)'))
|
2023-01-05 23:47:26 +11:00
|
|
|
drcr.plugins.account_kinds.append(('austax.income10', 'Gross interest (10)'))
|
2023-09-10 20:40:40 +10:00
|
|
|
drcr.plugins.account_kinds.append(('austax.income13', 'Partnerships and trusts (13)'))
|
|
|
|
#drcr.plugins.account_kinds.append(('austax.income18', 'Net capital gain (18)'))
|
|
|
|
drcr.plugins.account_kinds.append(('austax.income20', 'Foreign source income and foreign assets or property (20)'))
|
2023-01-27 21:49:29 +11:00
|
|
|
drcr.plugins.account_kinds.append(('austax.d2', 'Work-related travel expenses (D2)'))
|
2023-01-04 18:03:08 +11:00
|
|
|
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)'))
|
2023-07-03 22:32:23 +10:00
|
|
|
drcr.plugins.account_kinds.append(('austax.d9', 'Gifts or donations (D9)'))
|
2024-08-16 22:40:10 +10:00
|
|
|
drcr.plugins.account_kinds.append(('austax.d15', 'Other deductions (D15)'))
|
2023-09-10 20:54:47 +10:00
|
|
|
drcr.plugins.account_kinds.append(('austax.offset', 'Tax offset'))
|
2023-01-05 18:36:01 +11:00
|
|
|
drcr.plugins.account_kinds.append(('austax.paygw', 'PAYG withheld amounts'))
|
2023-01-07 02:05:21 +11:00
|
|
|
drcr.plugins.account_kinds.append(('austax.cgtasset', 'CGT asset'))
|
2023-05-28 14:06:09 +10:00
|
|
|
drcr.plugins.account_kinds.append(('austax.rfb', 'Reportable fringe benefit'))
|
2023-01-04 18:03:08 +11:00
|
|
|
|
|
|
|
drcr.plugins.transaction_providers.append(make_tax_transactions)
|
|
|
|
|
2024-11-09 18:14:25 +11:00
|
|
|
@assert_aud
|
2024-11-11 16:28:59 +11:00
|
|
|
def make_tax_transactions(transactions, start_date=None, end_date=None, api_stage_until=None):
|
|
|
|
if api_stage_until is not None and api_stage_until < 300:
|
|
|
|
return transactions
|
|
|
|
|
2023-01-04 18:03:08 +11:00
|
|
|
# Get EOFY date
|
2023-01-05 22:11:55 +11:00
|
|
|
dt = eofy_date()
|
2023-01-04 18:03:08 +11:00
|
|
|
|
2024-11-10 00:31:06 +11:00
|
|
|
if (start_date is not None and start_date > dt) or (end_date is not None and end_date < dt):
|
2024-11-11 15:30:18 +11:00
|
|
|
return transactions
|
2024-11-10 00:31:06 +11:00
|
|
|
|
2024-11-11 16:28:59 +11:00
|
|
|
# Get trial balance
|
|
|
|
balancer = TrialBalancer.from_cached(start_date=sofy_date(), end_date=dt)
|
|
|
|
balancer.apply_transactions(transactions)
|
|
|
|
|
|
|
|
report = tax_summary_report(balancer)
|
2024-11-10 00:31:06 +11:00
|
|
|
tax_amount = report.by_id('total_tax').amount - report.by_id('offsets').amount
|
|
|
|
|
2023-01-05 18:36:01 +11:00
|
|
|
# Estimated tax payable
|
2024-11-11 15:30:18 +11:00
|
|
|
transactions.append(Transaction(
|
2023-01-04 18:03:08 +11:00
|
|
|
dt=dt,
|
2023-01-05 18:36:01 +11:00
|
|
|
description='Estimated income tax',
|
2023-01-04 18:03:08 +11:00
|
|
|
postings=[
|
2024-11-09 18:14:25 +11:00
|
|
|
Posting(account='Income Tax', quantity=tax_amount.quantity, commodity=reporting_commodity()),
|
|
|
|
Posting(account='Income Tax Control', quantity=-tax_amount.quantity, commodity=reporting_commodity())
|
2023-01-04 18:03:08 +11:00
|
|
|
]
|
2024-11-11 15:30:18 +11:00
|
|
|
))
|
2023-01-05 18:36:01 +11:00
|
|
|
|
2023-01-05 22:11:55 +11:00
|
|
|
# Mandatory study loan repayment
|
|
|
|
loan_repayment = report.by_id('loan_repayment').amount
|
|
|
|
if loan_repayment.quantity != 0:
|
|
|
|
transactions.append(Transaction(
|
|
|
|
dt=dt,
|
|
|
|
description='Mandatory study loan repayment payable',
|
|
|
|
postings=[
|
2024-11-09 18:14:25 +11:00
|
|
|
Posting(account='HELP', quantity=loan_repayment.quantity, commodity=reporting_commodity()), # FIXME: Correct account
|
|
|
|
Posting(account='Income Tax Control', quantity=-loan_repayment.quantity, commodity=reporting_commodity())
|
2023-01-05 22:11:55 +11:00
|
|
|
]
|
|
|
|
))
|
|
|
|
|
2023-01-05 18:36:01 +11:00
|
|
|
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:
|
2023-05-28 13:04:40 +10:00
|
|
|
if account_name in accounts and accounts[account_name].quantity != 0:
|
2023-01-05 18:36:01 +11:00
|
|
|
# Transfer balance to Income Tax Control
|
|
|
|
transactions.append(Transaction(
|
|
|
|
dt=dt,
|
|
|
|
description='PAYG withheld amounts',
|
|
|
|
postings=[
|
2024-11-09 18:14:25 +11:00
|
|
|
Posting(account='Income Tax Control', quantity=accounts[account_name].quantity, commodity=reporting_commodity()),
|
|
|
|
Posting(account=account_name, quantity=-accounts[account_name].quantity, commodity=reporting_commodity())
|
2023-01-05 18:36:01 +11:00
|
|
|
]
|
|
|
|
))
|
|
|
|
|
|
|
|
return transactions
|