From 97893a9c1215d282eaa7cf0ee29d2ac51e55c5d4 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Mon, 11 Nov 2024 15:30:18 +1100 Subject: [PATCH] Provide running list of transactions to transaction providers This will enable transaction providers to act iteratively on the results of previous transaction providers --- austax/__init__.py | 9 +++++---- drcr/webapp.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/austax/__init__.py b/austax/__init__.py index 93997f0..04b6dde 100644 --- a/austax/__init__.py +++ b/austax/__init__.py @@ -49,25 +49,25 @@ def plugin_init(): drcr.plugins.transaction_providers.append(make_tax_transactions) @assert_aud -def make_tax_transactions(start_date=None, end_date=None): +def make_tax_transactions(transactions, start_date=None, end_date=None): # Get EOFY date dt = eofy_date() if (start_date is not None and start_date > dt) or (end_date is not None and end_date < dt): - return [] + return transactions report = tax_summary_report() tax_amount = report.by_id('total_tax').amount - report.by_id('offsets').amount # Estimated tax payable - transactions = [Transaction( + transactions.append(Transaction( dt=dt, description='Estimated income tax', postings=[ Posting(account='Income Tax', quantity=tax_amount.quantity, commodity=reporting_commodity()), Posting(account='Income Tax Control', quantity=-tax_amount.quantity, commodity=reporting_commodity()) ] - )] + )) # Mandatory study loan repayment loan_repayment = report.by_id('loan_repayment').amount @@ -83,6 +83,7 @@ def make_tax_transactions(start_date=None, end_date=None): # Get trial balance balancer = TrialBalancer.from_cached() + balancer.apply_transactions(transactions) accounts = dict(sorted(balancer.accounts.items())) diff --git a/drcr/webapp.py b/drcr/webapp.py index dae6e90..6bf7007 100644 --- a/drcr/webapp.py +++ b/drcr/webapp.py @@ -70,7 +70,7 @@ def api_transactions(start_date=None, end_date=None): # Plugins for transaction_provider in transaction_providers: - transactions.extend(transaction_provider(start_date=start_date, end_date=end_date)) + transactions = transaction_provider(transactions, start_date=start_date, end_date=end_date) return transactions