Provide running list of transactions to transaction providers

This will enable transaction providers to act iteratively on the results of previous transaction providers
This commit is contained in:
RunasSudo 2024-11-11 15:30:18 +11:00
parent 541086d346
commit 97893a9c12
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 6 additions and 5 deletions

View File

@ -49,25 +49,25 @@ def plugin_init():
drcr.plugins.transaction_providers.append(make_tax_transactions) drcr.plugins.transaction_providers.append(make_tax_transactions)
@assert_aud @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 # Get EOFY date
dt = 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): 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() report = tax_summary_report()
tax_amount = report.by_id('total_tax').amount - report.by_id('offsets').amount tax_amount = report.by_id('total_tax').amount - report.by_id('offsets').amount
# Estimated tax payable # Estimated tax payable
transactions = [Transaction( transactions.append(Transaction(
dt=dt, dt=dt,
description='Estimated income tax', description='Estimated income tax',
postings=[ postings=[
Posting(account='Income Tax', quantity=tax_amount.quantity, commodity=reporting_commodity()), Posting(account='Income Tax', quantity=tax_amount.quantity, commodity=reporting_commodity()),
Posting(account='Income Tax Control', quantity=-tax_amount.quantity, commodity=reporting_commodity()) Posting(account='Income Tax Control', quantity=-tax_amount.quantity, commodity=reporting_commodity())
] ]
)] ))
# Mandatory study loan repayment # Mandatory study loan repayment
loan_repayment = report.by_id('loan_repayment').amount 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 # Get trial balance
balancer = TrialBalancer.from_cached() balancer = TrialBalancer.from_cached()
balancer.apply_transactions(transactions)
accounts = dict(sorted(balancer.accounts.items())) accounts = dict(sorted(balancer.accounts.items()))

View File

@ -70,7 +70,7 @@ def api_transactions(start_date=None, end_date=None):
# Plugins # Plugins
for transaction_provider in transaction_providers: 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 return transactions