Display transaction detail w/ commodity in two-column Dr/Cr layout

This commit is contained in:
RunasSudo 2020-03-30 19:20:00 +11:00
parent 516afe9aed
commit d3cd7eebaa
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 51 additions and 9 deletions

View File

@ -22,6 +22,7 @@ from .model import *
from datetime import datetime, timedelta
from decimal import Decimal
import flask
import itertools
app = flask.Flask(__name__, template_folder='jinja2')
@ -199,12 +200,14 @@ def transaction():
transaction = next((t for t in l.transactions if str(t.id) == tid))
total_dr = sum((p.amount for p in transaction.postings if p.amount > 0), Balance()).exchange(report_currency, True)
total_cr = sum((p.amount for p in transaction.postings if p.amount < 0), Balance()).exchange(report_currency, True)
if commodity:
return flask.render_template('transaction_commodity.html', ledger=l, transaction=transaction, total_dr=total_dr, total_cr=total_cr, report_currency=report_currency, cash=cash)
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()
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_currency, True), total_cr=total_cr.exchange(report_currency, True), report_currency=report_currency, cash=cash)
else:
total_dr = sum((p.amount for p in transaction.postings if p.amount > 0), Balance()).exchange(report_currency, True)
total_cr = sum((p.amount for p in transaction.postings if p.amount < 0), Balance()).exchange(report_currency, True)
return flask.render_template('transaction.html', ledger=l, transaction=transaction, total_dr=total_dr, total_cr=total_cr, report_currency=report_currency, cash=cash)
# Template filters

View File

@ -41,8 +41,9 @@
{#<th style="width: 5em;">Date</th>#}
<th>Description</th>
<th style="max-width: 8em;">Account</th>
<th style="width: 1em;"></th>
<th style="text-align: right; width: 5em;">Amount</th>
<th style="text-align: right; width: 5em;">Dr</th>
<th style="width: 4em;"></th>
<th style="text-align: right; width: 5em;">Cr</th>
<th style="width: 4em;"></th>
</tr>
@ -51,10 +52,48 @@
<tr>
<td>{{ posting.comment }}</td>
<td>{{ (posting.account.name|e).__str__().replace(':', ':<wbr>')|safe }}</td>
<td>{% if posting.amount >= 0 %}Dr{% else %}Cr{% endif %}</td>
<td style="text-align: right;"><span title="{{ posting.amount.tostr(False) }}">{{ posting.amount|abs|bc }}</span></td>
<td>{% if posting.amount.currency.price %}<span title="{{ posting.amount.tostr(False) }}">{{ '{' + posting.amount.currency.price|bc + '}' }}</span>{% endif %}</td>
{% if posting.amount >= 0 %}
<td style="text-align: right;"><span title="{{ posting.amount.tostr(False) }}">{{ posting.amount|abs|bc }}</span></td>
<td>{% if posting.amount.currency.price %}<span title="{{ posting.amount.tostr(False) }}">{{ '{' + posting.amount.currency.price|bc + '}' }}</span>{% endif %}</td>
<td></td>
<td></td>
{% else %}
<td></td>
<td></td>
<td style="text-align: right;"><span title="{{ posting.amount.tostr(False) }}">{{ -posting.amount|abs|bc }}</span></td>
<td>{% if posting.amount.currency.price %}<span title="{{ posting.amount.tostr(False) }}">{{ '{' + posting.amount.currency.price|bc + '}' }}</span>{% endif %}</td>
{% endif %}
</tr>
{% endfor %}
{% for dr_amount, cr_amount in totals %}
<tr class="total explicit-rules" style="{% if loop.first %}border-top: 1pt solid black;{% endif %}{% if loop.last %}border-bottom: 1pt solid black;{% endif %}">
<td>{% if loop.first %}Total{% endif %}</td>
<td></td>
{% if dr_amount %}
<td style="text-align: right;"><span title="{{ dr_amount.tostr(False) }}">{{ dr_amount|abs|bc }}</span></td>
<td>{% if dr_amount.currency.price %}<span title="{{ dr_amount.tostr(False) }}">{{ '{' + dr_amount.currency.price|bc + '}' }}</span>{% endif %}</td>
{% else %}
<td></td>
<td></td>
{% endif %}
{% if cr_amount %}
<td style="text-align: right;"><span title="{{ cr_amount.tostr(False) }}">{{ -cr_amount|abs|bc }}</span></td>
<td>{% if cr_amount.currency.price %}<span title="{{ cr_amount.tostr(False) }}">{{ '{' + cr_amount.currency.price|bc + '}' }}</span>{% endif %}</td>
{% else %}
<td></td>
<td></td>
{% endif %}
</tr>
{% endfor %}
<tr class="total">
<td></td>
<td></td>
<td style="text-align: right;"><span title="{{ total_dr.tostr(False) }}">{{ total_dr|abs|bc }}</span></td>
<td></td>
<td style="text-align: right;"><span title="{{ total_cr.tostr(False) }}">{{ -total_cr|abs|bc }}</span></td>
<td></td>
</tr>
</table>
{% endblock %}