Process trial balance before displaying individual transaction

This is required to show unrealised gains, etc.
This commit is contained in:
RunasSudo 2020-07-17 11:31:35 +10:00
parent d87d49fc00
commit e1e28060e8
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
4 changed files with 9 additions and 5 deletions

View File

@ -304,6 +304,8 @@ def transactions():
@app.route('/transaction') @app.route('/transaction')
def transaction(): def transaction():
date = datetime.strptime(flask.request.args['date'], '%Y-%m-%d')
pstart = datetime.strptime(flask.request.args['pstart'], '%Y-%m-%d')
uuid = flask.request.args['uuid'] uuid = flask.request.args['uuid']
cash = flask.request.args.get('cash', False) cash = flask.request.args.get('cash', False)
commodity = flask.request.args.get('commodity', False) commodity = flask.request.args.get('commodity', False)
@ -314,17 +316,19 @@ def transaction():
if cash: if cash:
l = accounting.ledger_to_cash(l, report_commodity) l = accounting.ledger_to_cash(l, report_commodity)
l = accounting.trial_balance(l, date, pstart, report_commodity).ledger
transaction = next((t for t in l.transactions if str(t.uuid) == uuid)) transaction = next((t for t in l.transactions if str(t.uuid) == uuid))
if commodity: if commodity:
total_dr = sum((p.amount for p in transaction.postings if p.amount > 0), Balance()).clean() total_dr = sum((p.amount for p in transaction.postings if p.amount > 0), Balance()).clean()
total_cr = sum((p.amount for p in transaction.postings if p.amount < 0), Balance()).clean() total_cr = sum((p.amount for p in transaction.postings if p.amount < 0), Balance()).clean()
totals = itertools.zip_longest(total_dr.amounts, total_cr.amounts) totals = itertools.zip_longest(total_dr.amounts, total_cr.amounts)
return flask.render_template('transaction_commodity.html', ledger=l, transaction=transaction, totals=totals, total_dr=total_dr.exchange(report_commodity, True), total_cr=total_cr.exchange(report_commodity, True), report_commodity=report_commodity, cash=cash) return flask.render_template('transaction_commodity.html', ledger=l, transaction=transaction, totals=totals, total_dr=total_dr.exchange(report_commodity, True), total_cr=total_cr.exchange(report_commodity, True), report_commodity=report_commodity, cash=cash, date=date, pstart=pstart)
else: else:
total_dr = sum((p.amount for p in transaction.postings if p.amount > 0), Balance()).exchange(report_commodity, True) total_dr = sum((p.amount for p in transaction.postings if p.amount > 0), Balance()).exchange(report_commodity, True)
total_cr = sum((p.amount for p in transaction.postings if p.amount < 0), Balance()).exchange(report_commodity, True) total_cr = sum((p.amount for p in transaction.postings if p.amount < 0), Balance()).exchange(report_commodity, True)
return flask.render_template('transaction.html', ledger=l, transaction=transaction, total_dr=total_dr, total_cr=total_cr, report_commodity=report_commodity, cash=cash) return flask.render_template('transaction.html', ledger=l, transaction=transaction, total_dr=total_dr, total_cr=total_cr, report_commodity=report_commodity, cash=cash, date=date, pstart=pstart)
# Template filters # Template filters

View File

@ -22,7 +22,7 @@
{% block links %} {% block links %}
{{ super() }} {{ super() }}
<a href="/transaction?{{ {'uuid': transaction.uuid, 'cash': 'on' if cash else '', 'commodity': 'on'}|urlencode }}">Show commodity detail</a> <a href="/transaction?{{ {'date': date.strftime('%Y-%m-%d'), 'pstart': pstart.strftime('%Y-%m-%d'), 'uuid': transaction.uuid, 'cash': 'on' if cash else '', 'commodity': 'on'}|urlencode }}">Show commodity detail</a>
{% endblock %} {% endblock %}
{% block report %} {% block report %}

View File

@ -67,7 +67,7 @@
{% endif %} {% endif %}
{% for transaction in transactions %} {% for transaction in transactions %}
{% set trn_url = '/transaction?' + {'uuid': transaction.uuid, 'cash': 'on' if cash else ''}|urlencode %} {% set trn_url = '/transaction?' + {'date': date_end.strftime('%Y-%m-%d'), 'pstart': date_beg.strftime('%Y-%m-%d'), 'uuid': transaction.uuid, 'cash': 'on' if cash else ''}|urlencode %}
{% if transaction.has_comment_detail %} {% if transaction.has_comment_detail %}
<tr class="trn-first"> <tr class="trn-first">

View File

@ -66,7 +66,7 @@
{% set ns.balance = opening_balance %} {% set ns.balance = opening_balance %}
{% for transaction in transactions %} {% for transaction in transactions %}
{% set trn_url = '/transaction?' + {'uuid': transaction.uuid, 'cash': 'on' if cash else ''}|urlencode %} {% set trn_url = '/transaction?' + {'date': date_end.strftime('%Y-%m-%d'), 'pstart': date_beg.strftime('%Y-%m-%d'), 'uuid': transaction.uuid, 'cash': 'on' if cash else ''}|urlencode %}
{% for posting in transaction.postings if posting.account == account %} {% for posting in transaction.postings if posting.account == account %}
{% set ns.balance = ns.balance + posting.amount %} {% set ns.balance = ns.balance + posting.amount %}
{% endfor %} {% endfor %}