From 91c264e9cd5649ac4c500b1c1fc0763601203df5 Mon Sep 17 00:00:00 2001 From: Timotheus Pokorra Date: Wed, 24 Mar 2021 21:25:47 +0100 Subject: [PATCH 1/2] display small crypto amounts with more decimals fixes #23 --- apps/monitor/templates/monitor.html | 6 +++--- apps/monitor/templatetags/filter.py | 4 ++++ apps/transactions/templatetags/filter.py | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/monitor/templates/monitor.html b/apps/monitor/templates/monitor.html index e00d961..0e7463c 100644 --- a/apps/monitor/templates/monitor.html +++ b/apps/monitor/templates/monitor.html @@ -64,13 +64,13 @@ We have sold {{ c.crypto }} for {{ c.sold|floatformat:2 }} EUR
{% endif %} {% if c.amount_kept %} - Current value of our {{ c.amount_kept|floatformat:3 }} {{ 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|floatformat:3 }} {{ c.crypto }}
+ We have bought within the last 12 months: {{ c.bought_recently|formatcurrency }} {{ c.crypto }}
{% endif %} {% if c.bought_tax_free %} - We can sell without paying taxes: {{ c.bought_tax_free|floatformat:3 }} {{ c.crypto }} for {{ c.value_tax_free|floatformat:2 }} EUR
+ We can sell without paying taxes: {{ c.bought_tax_free|formatcurrency }} {{ c.crypto }} for {{ c.value_tax_free|floatformat:2 }} EUR
{% endif %}
My transactions
diff --git a/apps/monitor/templatetags/filter.py b/apps/monitor/templatetags/filter.py index e556ed3..8445b99 100644 --- a/apps/monitor/templatetags/filter.py +++ b/apps/monitor/templatetags/filter.py @@ -6,5 +6,9 @@ register = template.Library() def formatcurrency(value): if value > 100: return "%0.0f" % (value,) + if value < 0.01: + return "%0.5f" % (value,) + if value < 0.1: + return "%0.4f" % (value,) return "%0.2f" % (value,) diff --git a/apps/transactions/templatetags/filter.py b/apps/transactions/templatetags/filter.py index e556ed3..8c70706 100644 --- a/apps/transactions/templatetags/filter.py +++ b/apps/transactions/templatetags/filter.py @@ -6,5 +6,9 @@ register = template.Library() def formatcurrency(value): if value > 100: return "%0.0f" % (value,) + if value < 0.01: + return "%0.4f" % (value,) + if value < 0.1: + return "%0.3f" % (value,) return "%0.2f" % (value,) From 6feb0e3ab5c1e3ddf4f5be4c753ff00a84b52cb5 Mon Sep 17 00:00:00 2001 From: Timotheus Pokorra Date: Wed, 24 Mar 2021 21:27:09 +0100 Subject: [PATCH 2/2] deal with transfers of once crypto currency between wallets fixes #24 --- apps/monitor/calc.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/monitor/calc.py b/apps/monitor/calc.py index 0778f1e..b96952a 100644 --- a/apps/monitor/calc.py +++ b/apps/monitor/calc.py @@ -85,6 +85,15 @@ class Calc: else: out["sold"] = None + # moving coins to other wallet with fees. + with connection.cursor() as cursor: + sql = """SELECT SUM(amount_after_fee) as after_fee FROM `transaction` WHERE amount_before_fee = 0 and crypto_currency=%s and owner_id=%s""" + cursor.execute(sql, [crypto, userid]) + sold = cursor.fetchone() + if sold[0]: + # total_investment -= Decimal(sold[1]) + amount_kept += Decimal(sold[0]) + rateEUR = ExchangeRate.objects.filter(crypto_currency=crypto, fiat_currency='EUR').order_by('-datetime_valid').first() rateUSD = ExchangeRate.objects.filter(crypto_currency=crypto, fiat_currency='USD').order_by('-datetime_valid').first()