Bank: add sign to money log.

This commit is contained in:
Casper V. Kristensen 2020-06-01 18:42:03 +02:00
parent 1d6cb59293
commit a22e3dba47
Signed by: caspervk
GPG key ID: 289CA03790535054
2 changed files with 4 additions and 5 deletions

View file

@ -22,7 +22,7 @@
{{ transaction.date }}
</td>
<td class="align-middle text-right {% if transaction.amount < 0 %}text-danger{% else %}text-success{% endif %}">
{% format_money transaction.amount %}
{% format_money transaction.amount force_sign=True %}
</td>
<td class="align-middle text-right">
{% format_money transaction.balance %}

View file

@ -6,10 +6,9 @@ register = template.Library()
@register.simple_tag()
def format_money(copper: int):
balance_str = str(abs(copper)).rjust(5, "0") # pad until 0 gold
if copper < 0:
balance_str = "-" + balance_str
def format_money(copper: int, force_sign=False):
sign = "+" if force_sign else "-"
balance_str = f"{copper:{sign}06}" # force sign if requested and zero-pad until 0 gold
return format_html(
"""
<span>