From ef711f18281033b97301027bb5bc71b1e376d8d3 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sun, 10 Nov 2024 00:31:27 +1100 Subject: [PATCH] Allow preparing trial balance and income statement reports at arbitrary dates --- drcr/views.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drcr/views.py b/drcr/views.py index 83dd940..a187372 100644 --- a/drcr/views.py +++ b/drcr/views.py @@ -22,6 +22,7 @@ from .plugins import account_kinds, advanced_reports, data_sources from .reports import balance_sheet_report, income_statement_report from .webapp import all_transactions, api_transactions, app +from datetime import datetime from itertools import groupby @app.route('/') @@ -69,8 +70,10 @@ def general_ledger(): @app.route('/trial-balance') def trial_balance(): - balancer = TrialBalancer.from_cached() - balancer.apply_transactions(api_transactions()) + dt = datetime.strptime(request.args['date'], '%Y-%m-%d') if 'date' in request.args else None + + balancer = TrialBalancer.from_cached(end_date=dt) + balancer.apply_transactions(api_transactions(end_date=dt)) total_dr = Amount(sum(v.quantity for v in balancer.accounts.values() if v.quantity > 0), reporting_commodity()) total_cr = Amount(sum(v.quantity for v in balancer.accounts.values() if v.quantity < 0), reporting_commodity()) @@ -126,5 +129,13 @@ def balance_sheet(): @app.route('/income-statement') def income_statement(): - report = income_statement_report() + if 'end_date' in request.args: + start_date = datetime.strptime(request.args['start_date'], '%Y-%m-%d') if 'start_date' in request.args else datetime.min + end_date = datetime.strptime(request.args['end_date'], '%Y-%m-%d') + + print(end_date) + else: + start_date, end_date = None, None + + report = income_statement_report(start_date=start_date, end_date=end_date) return render_template('report.html', report=report)