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: else:
return flask.Markup('{:,.2f} {}'.format(amt.amount, amt.currency.name).replace(',', ' ')) 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 # Debug views
@app.route('/debug/noncash_transactions') @app.route('/debug/noncash_transactions')

View File

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

View File

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