From 2818d9c11f066ae1ce318a108a9612b625644ad5 Mon Sep 17 00:00:00 2001 From: Timotheus Pokorra Date: Tue, 11 May 2021 22:30:57 +0200 Subject: [PATCH] various fixes --- apps/monitor/calc.py | 4 ++-- apps/monitor/templates/monitor.html | 2 +- apps/monitor/templatetags/filter.py | 2 ++ apps/transactions/templates/show.html | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/monitor/calc.py b/apps/monitor/calc.py index 5526fd4..4c62820 100644 --- a/apps/monitor/calc.py +++ b/apps/monitor/calc.py @@ -87,10 +87,10 @@ class Calc: # calculate all fees. with connection.cursor() as cursor: - sql = """SELECT SUM(crypto_fee) as crypto_fee, SUM(fiat_fee) as fiat_fee FROM `transaction` WHERE crypto_currency=%s and owner_id=%s""" + sql = """SELECT SUM(crypto_fee) as crypto_fee, SUM(fiat_fee) as fiat_fee FROM `transaction` WHERE crypto_currency=%s and owner_id=%s and transaction_type in ('T','B')""" cursor.execute(sql, [crypto, userid]) fees = cursor.fetchone() - if sold[0]: + if fees[0]: total_investment -= Decimal(fees[1]) amount_kept -= Decimal(fees[0]) diff --git a/apps/monitor/templates/monitor.html b/apps/monitor/templates/monitor.html index 0e7463c..7c58c1a 100644 --- a/apps/monitor/templates/monitor.html +++ b/apps/monitor/templates/monitor.html @@ -64,7 +64,7 @@ We have sold {{ c.crypto }} for {{ c.sold|floatformat:2 }} EUR
{% endif %} {% if c.amount_kept %} - Current value of our {{ c.amount_kept|formatcurrency }} {{ c.crypto }} is {{ c.current_value|floatformat:2 }} EUR
+ Current value of our {{ c.amount_kept|formatcurrency }} {{ c.crypto }} is {{ c.current_value|floatformat:2 }} EUR
{% endif %} {% if c.bought_recently %} We have bought within the last 12 months: {{ c.bought_recently|formatcurrency }} {{ c.crypto }}
diff --git a/apps/monitor/templatetags/filter.py b/apps/monitor/templatetags/filter.py index 8445b99..e882f68 100644 --- a/apps/monitor/templatetags/filter.py +++ b/apps/monitor/templatetags/filter.py @@ -4,6 +4,8 @@ register = template.Library() @register.filter def formatcurrency(value): + if not value: + return "0.00" if value > 100: return "%0.0f" % (value,) if value < 0.01: diff --git a/apps/transactions/templates/show.html b/apps/transactions/templates/show.html index b2581ea..49b95ae 100644 --- a/apps/transactions/templates/show.html +++ b/apps/transactions/templates/show.html @@ -23,11 +23,11 @@ {{ transaction.date_valid }} {{ transaction.crypto_amount|floatformat:3 }} - {% if transaction.crypto_fee > 0 %}Fee: {{ transaction.crypto_fee|floatformat:3 }}{% endif %} + {% if transaction.crypto_fee and transaction.crypto_fee > 0 %}Fee: {{ transaction.crypto_fee|floatformat:3 }}{% endif %} {{ transaction.crypto_currency }} {{ transaction.fiat_amount|formatcurrency }} - {% if transaction.fiat_fee > 0 %}Fee: {{ transaction.fiat_fee|floatformat:2 }}{% endif %} + {% if transaction.fiat_fee and transaction.fiat_fee > 0 %}Fee: {{ transaction.fiat_fee|floatformat:2 }}{% endif %} {{ transaction.fiat_currency }} {% if transaction.transaction_type == 'S' %}