Better align values in "with commodity" reports

This commit is contained in:
RunasSudo 2020-03-30 19:51:02 +11:00
parent f789817371
commit bc52ccc349
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 57 additions and 43 deletions

View File

@ -233,6 +233,29 @@ def filter_currency_positive(amt):
else:
return flask.Markup('{:,.2f} {}'.format(amt.amount, amt.currency.name).replace(',', ' '))
@app.template_filter('bt')
def filter_currency_table_positive(amt, show_price, link=None):
result = []
if amt.currency.is_prefix:
amt_str = filter_currency_positive(amt)
cur_str = ''
else:
amt_str = '{:,.2f}'.format(amt.amount).replace(',', ' ')
cur_str = amt.currency.name
amt_full = amt.tostr(False)
result.append('<td style="text-align: right;"><a href="{}"><span title="{}">{}</span></a></td>'.format(link, amt_full, amt_str) if link else '<td style="text-align: right;"><span title="{}">{}</span></td>'.format(amt_full, amt_str))
result.append('<td><span title="{}">{}</span></td>'.format(amt_full, cur_str))
if show_price:
if amt.currency.price:
result.append('<td><span title="{}">{{{}}}</span></td>'.format(amt_full, filter_currency_positive(amt.currency.price)))
else:
result.append('<td></td>')
return flask.Markup(''.join(result))
# Debug views
@app.route('/debug/noncash_transactions')

View File

@ -41,10 +41,12 @@
{#<th style="width: 5em;">Date</th>#}
<th>Description</th>
<th style="max-width: 8em;">Account</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>
<th style="text-align: right; width: 4em;">Dr</th> {# Amount #}
<th style="width: 2em;"></th> {# Currency #}
<th style="width: 2em;"></th> {# Price #}
<th style="text-align: right; width: 4em;">Cr</th>
<th style="width: 2em;"></th>
<th style="width: 2em;"></th>
</tr>
{% for posting in transaction.postings %}
@ -53,15 +55,11 @@
<td>{{ posting.comment }}</td>
<td>{{ (posting.account.name|e).__str__().replace(':', ':<wbr>')|safe }}</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>
{{ posting.amount|bt(True) }}
<td colspan="3"></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>
<td colspan="3"></td>
{{ -posting.amount|bt(True) }}
{% endif %}
</tr>
{% endfor %}
@ -71,18 +69,14 @@
<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>
{{ dr_amount|bt(True) }}
{% else %}
<td></td>
<td></td>
<td colspan="3"></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>
{{ -cr_amount|bt(True) }}
{% else %}
<td></td>
<td></td>
<td colspan="3"></td>
{% endif %}
</tr>
{% endfor %}
@ -90,10 +84,8 @@
<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>
{{ total_dr|bt(True) }}
{{ -total_cr|bt(True) }}
</tr>
</table>
{% endblock %}

View File

@ -29,25 +29,25 @@
<tr>
<th style="width: 5em;">Date</th>
<th>Description</th>
<th style="width: 1em;"></th>
<th style="text-align: right; width: 5em;">Amount</th>
{#<th style="width: 4em;"></th>#}
<th style="text-align: right; width: 5em;">Balance</th>
<th style="width: 4em;"></th>
<th style="width: 1em;"></th> {# Dr/Cr #}
<th style="text-align: right; width: 4em;">Amount</th>
<th style="width: 2em;"></th> {# Currency #}
<th style="text-align: right; width: 4em;">Balance</th>
<th style="width: 2em;"></th> {# Currency #}
<th style="width: 2em;"></th> {# Price #}
<th style="width: 1em;"></th>
</tr>
{% set ns = namespace(balance=None) %}
{% set prevlink = '/transactions_commodity?' + {'date': (pstart - timedelta(days=1)).strftime('%Y-%m-%d'), 'pstart': pstart.replace(year=pstart.year-1).strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode %}
{% set prevlink = '/transactions?' + {'date': (pstart - timedelta(days=1)).strftime('%Y-%m-%d'), 'pstart': pstart.replace(year=pstart.year-1).strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else '', 'commodity': 'on'}|urlencode %}
{% for amount in opening_balance.amounts %}
<tr class="total">
<td>{% if loop.first %}<a href="{{ prevlink }}">{{ pstart.strftime('%Y-%m-%d') }}</a>{% endif %}</td>
<td>{% if loop.first %}<a href="{{ prevlink }}">Opening Balance</a>{% endif %}</td>
<td></td>
{#<td></td>#}
<td></td>
<td style="text-align: right;"><a href="{{ prevlink }}"><span title="{{ amount.tostr(False) }}">{{ amount|abs|bc }}</span></a></td>
<td>{% if amount.currency.price %}<span title="{{ amount.tostr(False) }}">{{ '{' + amount.currency.price|bc + '}' }}</span>{% endif %}</td>
<td></td>
{{ amount|bt(True, prevlink) }}
<td>{% if amount >= 0 %}Dr{% else %}Cr{% endif %}</td>
</tr>
{% else %}
@ -56,8 +56,10 @@
<td><a href="{{ prevlink }}">Opening Balance</a></td>
<td></td>
<td></td>
<td></td>
<td style="text-align: right;"><a href="{{ prevlink }}">0.00</a></td>
<td></td>
<td></td>
<td>Dr</td>
</tr>
{% endfor %}
@ -75,13 +77,11 @@
<td>{% if loop.first %}{% if transaction.id %}<a href="{{ trn_url }}">{% endif %}{{ transaction.description }}{% if transaction.id %}</a>{% endif %}{% endif %}</td>
{% if posting %}
<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 %}{{ '{' + posting.amount.currency.price|bc + '}' }}{% endif %}</td>#}
{{ posting.amount|abs|bt(False) }}
{% else %}
<td colspan="2"></td>
<td colspan="3"></td>
{% endif %}
<td style="text-align: right;"><span title="{{ amount.tostr(False) }}">{{ amount|abs|bc }}</span></td>
<td>{% if amount.currency.price %}<span title="{{ amount.tostr(False) }}">{{ '{' + amount.currency.price|bc + '}' }}</span>{% endif %}</td>
{{ amount|abs|bt(True) }}
<td>{% if amount >= 0 %}Dr{% else %}Cr{% endif %}</td>
</tr>
{% endfor %}
@ -93,10 +93,9 @@
<td>{% if loop.first %}{{ date.strftime('%Y-%m-%d') }}{% endif %}</td>
<td>{% if loop.first %}Closing Balance{% endif %}</td>
<td></td>
{#<td></td>#}
<td></td>
<td style="text-align: right;"><span title="{{ amount.tostr(False) }}">{{ amount|abs|bc }}</span></td>
<td>{% if amount.currency.price %}<span title="{{ amount.tostr(False) }}">{{ '{' + amount.currency.price|bc + '}' }}</span>{% endif %}</td>
<td></td>
{{ amount|bt(True) }}
<td>{% if amount >= 0 %}Dr{% else %}Cr{% endif %}</td>
</tr>
{% endfor %}
@ -106,9 +105,9 @@
<td></td>
<td></td>
<td></td>
{% set closing_balance = closing_balance.exchange(report_currency, True) %}
<td style="text-align: right;"><span title="{{ closing_balance.tostr(False) }}">{{ closing_balance|abs|bc }}</span></td>
<td></td>
{% set closing_balance = closing_balance.exchange(report_currency, True) %}
{{ closing_balance|bt(True) }}
<td>{% if closing_balance >= 0 %}Dr{% else %}Cr{% endif %}</td>
</tr>
</table>