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 }} {{ transaction.date }}
</td> </td>
<td class="align-middle text-right {% if transaction.amount < 0 %}text-danger{% else %}text-success{% endif %}"> <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>
<td class="align-middle text-right"> <td class="align-middle text-right">
{% format_money transaction.balance %} {% format_money transaction.balance %}

View file

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