From b34ec8473e35e9d8dacd86c87e610a22f818eb63 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sat, 24 Dec 2022 16:43:08 +1100 Subject: [PATCH] Add account transactions view --- drcr/templates/transactions.html | 89 +++++++++++++++++++++++++++++++ drcr/templates/trial_balance.html | 2 +- drcr/views.py | 14 ++++- 3 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 drcr/templates/transactions.html diff --git a/drcr/templates/transactions.html b/drcr/templates/transactions.html new file mode 100644 index 0000000..38f20af --- /dev/null +++ b/drcr/templates/transactions.html @@ -0,0 +1,89 @@ +{# 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 . +#} + +{% extends 'base.html' %} +{% block title %}Account transactions{% endblock %} + +{% block body %} +
+

Account transactions

+ + + + + + + + + + + + + + + {% for transaction in transactions %} + {% if transaction.postings|length == 2 %} + {% for posting in transaction.postings if posting.account == account %} + {% set _ = running_total.__setattr__('quantity', running_total.quantity + posting.quantity) %} + + + + + + + + + + {% endfor %} + {% else %} + + + + + + + + + {% for posting in transaction.postings if posting.account == account %} + {% set _ = running_total.__setattr__('quantity', running_total.quantity + posting.quantity) %} + + + + + + + + + + {% endfor %} + {% for posting in transaction.postings if posting.account != account %} + + + + + + + + + + {% endfor %} + {% endif %} + {% endfor %} + +
DateDescriptionRelated AccountDrCrBalance
{{ transaction.dt.strftime('%Y-%m-%d') }}{{ transaction.description }}{% for p in transaction.postings if p.account != account %}{{ p.account }}{% endfor %}{{ posting.amount().format() if posting.quantity >= 0 else '' }}{{ (posting.amount()|abs).format() if posting.quantity < 0 else '' }}{{ (running_total|abs).format() }}{{ 'Dr' if running_total.quantity >= 0 else 'Cr' }}
{{ transaction.dt.strftime('%Y-%m-%d') }}{{ transaction.description }}
{{ 'Dr' if posting.quantity >= 0 else 'Cr' }}{{ account }}{{ posting.amount().format() if posting.quantity >= 0 else '' }}{{ (posting.amount()|abs).format() if posting.quantity < 0 else '' }}{{ (running_total|abs).format() }}{{ 'Dr' if running_total.quantity >= 0 else 'Cr' }}
{{ 'Dr' if posting.quantity >= 0 else 'Cr' }}{{ posting.account }}{{ posting.amount().format() if posting.quantity >= 0 else '' }}{{ (posting.amount()|abs).format() if posting.quantity < 0 else '' }}
+
+{% endblock %} diff --git a/drcr/templates/trial_balance.html b/drcr/templates/trial_balance.html index 7cd6243..e716318 100644 --- a/drcr/templates/trial_balance.html +++ b/drcr/templates/trial_balance.html @@ -33,7 +33,7 @@ {% for name, balance in accounts.items() %} - {{ name }} + {{ name }} {{ balance.format() if balance.quantity >= 0 else '' }} {{ (balance|abs).format() if balance.quantity < 0 else '' }} diff --git a/drcr/views.py b/drcr/views.py index 60b1072..e079454 100644 --- a/drcr/views.py +++ b/drcr/views.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from flask import render_template +from flask import render_template, request from .models import Amount, TrialBalancer from .webapp import all_transactions, app @@ -36,3 +36,15 @@ def trial_balance(): total_cr = Amount(sum(v.quantity for v in balancer.accounts.values() if v.quantity < 0), '$') return render_template('trial_balance.html', accounts=dict(sorted(balancer.accounts.items())), total_dr=total_dr, total_cr=total_cr) + +@app.route('/account-transactions') +def account_transactions(): + # FIXME: Filter in SQL + transactions = [t for t in all_transactions() if any(p.account == request.args['account'] for p in t.postings)] + + return render_template( + 'transactions.html', + account=request.args['account'], + running_total=Amount(0, '$'), + transactions=sorted(transactions, key=lambda t: t.dt) + )