DrCr/drcr/reports/views.py

37 lines
1.5 KiB
Python
Raw Normal View History

2022-12-24 15:14:19 +11:00
# DrCr: Web-based double-entry bookkeeping framework
# Copyright (C) 2022 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 flask import render_template
from ..config import BALANCE_SHEET_MAPPING, COA_MAPPING
2022-12-24 15:14:19 +11:00
from ..models import Amount, TrialBalancer
from ..webapp import all_transactions, app
@app.route('/reports/balance-sheet')
def balance_sheet():
# Extract trial balance
balancer = TrialBalancer()
balancer.apply_transactions(all_transactions())
# Classify accounts
for source_account, destination_account in COA_MAPPING.items():
balancer.transfer_balance(source_account, destination_account)
balancer.transfer_balance('Income', 'Current year surplus (deficit)')
balancer.transfer_balance('Expenses', 'Current year surplus (deficit)')
2022-12-24 15:14:19 +11:00
return render_template('reports/balance_sheet.html', accounts=balancer.accounts, running_total=Amount(0, '$'), BALANCE_SHEET_MAPPING=BALANCE_SHEET_MAPPING)