From 68c26eb924e1df2d1016ef88b7b27bfdd35f8b2b Mon Sep 17 00:00:00 2001 From: Timotheus Pokorra Date: Wed, 12 May 2021 06:54:32 +0200 Subject: [PATCH] fix for fees for selling. fix for taxfree amount. add description to transactions. --- apps/monitor/calc.py | 7 ++- apps/transactions/importbtcde.py | 2 +- .../migrations/0006_auto_20210511_2230.py | 44 +++++++++++++++++++ apps/transactions/models.py | 1 + apps/transactions/templates/add.html | 7 +++ apps/transactions/templates/edit.html | 7 +++ apps/transactions/templates/show.html | 5 +++ 7 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 apps/transactions/migrations/0006_auto_20210511_2230.py diff --git a/apps/monitor/calc.py b/apps/monitor/calc.py index 4c62820..42dade8 100644 --- a/apps/monitor/calc.py +++ b/apps/monitor/calc.py @@ -87,7 +87,7 @@ 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 and transaction_type in ('T','B')""" + sql = """SELECT SUM(crypto_fee) as crypto_fee, SUM(fiat_fee) as fiat_fee FROM `transaction` WHERE crypto_currency=%s and owner_id=%s""" cursor.execute(sql, [crypto, userid]) fees = cursor.fetchone() if fees[0]: @@ -137,7 +137,10 @@ class Calc: if bought[0]: out["bought_recently"] = bought[0] amount_within_past_year = Decimal(bought[0]) - amount_available_to_sell = amount_kept - amount_within_past_year + if amount_kept > amount_within_past_year: + amount_available_to_sell = amount_kept - amount_within_past_year + else: + amount_available_to_sell = 0 out["bought_tax_free"] = None out["value_tax_free"] = None if rateEUR: diff --git a/apps/transactions/importbtcde.py b/apps/transactions/importbtcde.py index 4d0c5ea..d246176 100644 --- a/apps/transactions/importbtcde.py +++ b/apps/transactions/importbtcde.py @@ -37,7 +37,7 @@ class ImportBtcDe: if trade['trading_pair'].upper().endswith(f): t.fiat_currency = f t.owner = Owner - t.crypto_amount = Decimal(trade['amount_currency_to_trade']) + t.crypto_amount = Decimal(trade['amount_currency_to_trade'])-Decimal(trade['amount_currency_to_trade']) t.crypto_fee = Decimal(trade['fee_currency_to_trade']) t.fiat_amount = Decimal(trade['volume_currency_to_pay']) t.fiat_fee = Decimal(trade['fee_currency_to_pay']) diff --git a/apps/transactions/migrations/0006_auto_20210511_2230.py b/apps/transactions/migrations/0006_auto_20210511_2230.py new file mode 100644 index 0000000..2763be6 --- /dev/null +++ b/apps/transactions/migrations/0006_auto_20210511_2230.py @@ -0,0 +1,44 @@ +# Generated by Django 3.2.2 on 2021-05-11 20:30 + +import apps.transactions.models +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('transactions', '0005_auto_20210511_1638'), + ] + + operations = [ + migrations.AddField( + model_name='transaction', + name='description', + field=models.CharField(blank=True, max_length=100, null=True), + ), + migrations.AlterField( + model_name='transaction', + name='crypto_amount', + field=apps.transactions.models.NonscientificDecimalField(blank=True, decimal_places=10, max_digits=24, null=True), + ), + migrations.AlterField( + model_name='transaction', + name='crypto_fee', + field=apps.transactions.models.NonscientificDecimalField(blank=True, decimal_places=10, max_digits=24, null=True), + ), + migrations.AlterField( + model_name='transaction', + name='exchange_rate', + field=apps.transactions.models.NonscientificDecimalField(decimal_places=10, max_digits=24), + ), + migrations.AlterField( + model_name='transaction', + name='fiat_amount', + field=apps.transactions.models.NonscientificDecimalField(blank=True, decimal_places=10, max_digits=24, null=True), + ), + migrations.AlterField( + model_name='transaction', + name='fiat_fee', + field=apps.transactions.models.NonscientificDecimalField(blank=True, decimal_places=10, max_digits=24, null=True), + ), + ] diff --git a/apps/transactions/models.py b/apps/transactions/models.py index 11cd5ae..dcee8a9 100644 --- a/apps/transactions/models.py +++ b/apps/transactions/models.py @@ -40,6 +40,7 @@ class Transaction(models.Model): fiat_fee = NonscientificDecimalField(max_digits=24, decimal_places=10, null=True, blank=True) date_valid = models.DateTimeField('date transfered') transaction_type = models.CharField(max_length=1, choices=TRANSACTION_TYPES, default='B') + description = models.CharField(max_length=100, null=True, blank=True) class Meta: db_table = "transaction" diff --git a/apps/transactions/templates/add.html b/apps/transactions/templates/add.html index 224ab67..74d01d4 100644 --- a/apps/transactions/templates/add.html +++ b/apps/transactions/templates/add.html @@ -98,6 +98,13 @@ +
+ +
+ {{ form.description }} +
+
+
diff --git a/apps/transactions/templates/edit.html b/apps/transactions/templates/edit.html index 6febc61..79e44a1 100644 --- a/apps/transactions/templates/edit.html +++ b/apps/transactions/templates/edit.html @@ -92,6 +92,13 @@
+
+ +
+ {{ form.description }} +
+
+
diff --git a/apps/transactions/templates/show.html b/apps/transactions/templates/show.html index 49b95ae..281e55d 100644 --- a/apps/transactions/templates/show.html +++ b/apps/transactions/templates/show.html @@ -20,6 +20,11 @@ {% for transaction in transactions %} + {% if transaction.description and transaction.description != '' %} + + {{ transaction.description }}: + + {% endif %} {{ transaction.date_valid }} {{ transaction.crypto_amount|floatformat:3 }}