smaller fixes for recent changes
This commit is contained in:
@@ -90,8 +90,9 @@ class Calc:
|
|||||||
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"""
|
||||||
cursor.execute(sql, [crypto, userid])
|
cursor.execute(sql, [crypto, userid])
|
||||||
fees = cursor.fetchone()
|
fees = cursor.fetchone()
|
||||||
if fees[0]:
|
if fees[1]:
|
||||||
total_investment -= Decimal(fees[1])
|
total_investment -= Decimal(fees[1])
|
||||||
|
if fees[0]:
|
||||||
amount_kept -= Decimal(fees[0])
|
amount_kept -= Decimal(fees[0])
|
||||||
|
|
||||||
rateEUR = ExchangeRate.objects.filter(crypto_currency=crypto, fiat_currency='EUR').order_by('-datetime_valid').first()
|
rateEUR = ExchangeRate.objects.filter(crypto_currency=crypto, fiat_currency='EUR').order_by('-datetime_valid').first()
|
||||||
|
|||||||
@@ -26,15 +26,17 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ transaction.date_valid }}</td>
|
<td>{{ transaction.date_valid }}</td>
|
||||||
<td>{{ transaction.crypto_amount|floatformat:3 }}
|
<td><span title="{% if transaction.crypto_fee and transaction.crypto_fee > 0 %}Fee: {{ transaction.crypto_fee }}{% else %}{{ transaction.crypto_total }}{% endif %}">
|
||||||
{% if transaction.crypto_fee and transaction.crypto_fee > 0 %}Fee: {{ transaction.crypto_fee|floatformat:3 }}{% endif %}
|
{{ transaction.crypto_total|floatformat:3 }}
|
||||||
{{ transaction.crypto_currency }}
|
{{ transaction.crypto_currency }}
|
||||||
</td>
|
</span>
|
||||||
<td>{{ transaction.fiat_amount|formatcurrency }}
|
</td>
|
||||||
{% if transaction.fiat_fee and transaction.fiat_fee > 0 %}Fee: {{ transaction.fiat_fee|floatformat:2 }}{% endif %}
|
<td><span title="{% if transaction.fiat_fee and transaction.fiat_fee > 0 %}Fee: {{ transaction.fiat_fee }}{% else %}{{ transaction.fiat_total }}{% endif %}">
|
||||||
{{ transaction.fiat_currency }}
|
{{ transaction.fiat_total|formatcurrency }}
|
||||||
</td>
|
{{ transaction.fiat_currency }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
<td>{% if transaction.transaction_type == 'S' %}
|
<td>{% if transaction.transaction_type == 'S' %}
|
||||||
{{ transaction.exchange_rate|formatcurrency }} {{ transaction.crypto_currency }}/{{ transaction.fiat_currency }}
|
{{ transaction.exchange_rate|formatcurrency }} {{ transaction.crypto_currency }}/{{ transaction.fiat_currency }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.db.models import Value
|
||||||
from apps.transactions.forms import TransactionForm
|
from apps.transactions.forms import TransactionForm
|
||||||
from apps.transactions.forms import ImportForm
|
from apps.transactions.forms import ImportForm
|
||||||
from apps.transactions.models import Transaction
|
from apps.transactions.models import Transaction
|
||||||
@@ -43,9 +44,20 @@ def importbtcde(request):
|
|||||||
@login_required
|
@login_required
|
||||||
def show(request):
|
def show(request):
|
||||||
if 'crypto' in request.GET:
|
if 'crypto' in request.GET:
|
||||||
transactions = Transaction.objects.filter(owner=request.user, crypto_currency=request.GET['crypto']).order_by('-date_valid')
|
transactions = Transaction.objects.filter(owner=request.user, crypto_currency=request.GET['crypto']).order_by('-date_valid').annotate(crypto_total=Value(0.0), fiat_total=Value(0.0))
|
||||||
else:
|
else:
|
||||||
transactions = Transaction.objects.filter(owner=request.user).order_by('-date_valid')
|
transactions = Transaction.objects.filter(owner=request.user).order_by('-date_valid').annotate(crypto_total=Value(0.0), fiat_total=Value(0.0))
|
||||||
|
for tr in transactions:
|
||||||
|
tr.crypto_total = 0.0
|
||||||
|
if tr.crypto_amount:
|
||||||
|
tr.crypto_total += float(tr.crypto_amount)
|
||||||
|
if tr.crypto_fee:
|
||||||
|
tr.crypto_total += float(tr.crypto_fee)
|
||||||
|
tr.fiat_total = 0.0
|
||||||
|
if tr.fiat_amount:
|
||||||
|
tr.fiat_total += float(tr.fiat_amount)
|
||||||
|
if tr.fiat_fee:
|
||||||
|
tr.fiat_total += float(tr.fiat_fee)
|
||||||
return render(request,"show.html",{'transactions':transactions})
|
return render(request,"show.html",{'transactions':transactions})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
+9
-9
@@ -2,13 +2,13 @@
|
|||||||
update auth_user set password = 'pbkdf2_sha256$216000$FXCqxdaIG4Dd$QCQEUACd3srB68dlqjekrbHYwThyY3EOQxctr6u0hYQ=', username='demo', email='demo@solidcharity.com' where id='3';
|
update auth_user set password = 'pbkdf2_sha256$216000$FXCqxdaIG4Dd$QCQEUACd3srB68dlqjekrbHYwThyY3EOQxctr6u0hYQ=', username='demo', email='demo@solidcharity.com' where id='3';
|
||||||
delete from `transaction` where owner_id=3;
|
delete from `transaction` where owner_id=3;
|
||||||
|
|
||||||
insert into `transaction`(crypto_currency, amount_before_fee, amount_after_fee, exchange_rate, fiat_currency, amount, date_valid, owner_id)
|
insert into `transaction`(crypto_currency, transaction_type, crypto_amount, crypto_fee, exchange_rate, fiat_currency, fiat_amount, date_valid, owner_id)
|
||||||
values
|
values
|
||||||
('BTC',0.10,0.0990, 754.25,'EUR', 75.42,'2016-12-16 00:00:00.000000',3),
|
('BTC','B',0.0990,0.001,754.25,'EUR', 75.42,'2016-12-16 00:00:00.000000',3),
|
||||||
('BTC',0.20,0.199, 555.32,'EUR',150.85,'2016-09-09 00:00:00.000000',3),
|
('BTC','B',0.199,0.001,555.32,'EUR',150.85,'2016-09-09 00:00:00.000000',3),
|
||||||
('BTC',0.03,0.0299,9988.17,'EUR',299.64,'2020-08-07 00:00:00.000000',3),
|
('BTC','B',0.0299,0.0001,9988.17,'EUR',299.64,'2020-08-07 00:00:00.000000',3),
|
||||||
('BTC',-0.15,-0.149,14210.97,'EUR',-2131.64,'2018-01-05 00:10:00.000000',3),
|
('BTC','S',0.149,0.001,14210.97,'EUR',2131.64,'2018-01-05 00:10:00.000000',3),
|
||||||
('BCH',0.298,0.298,200.00,'EUR',0.0,'2017-01-08 00:00:00.000000',3),
|
('BCH','B',0.298,0,200.00,'EUR',0.0,'2017-01-08 00:00:00.000000',3),
|
||||||
('ETH',0.1,0.099,592.15,'EUR',59.21,'2017-12-29 00:12:00.000000',3),
|
('ETH','B',0.099,0.001,592.15,'EUR',59.21,'2017-12-29 00:12:00.000000',3),
|
||||||
('ETH',1.0,0.99,100.88,'EUR',100.88,'2019-01-26 00:17:00.000000',3),
|
('ETH','B',0.99,0.01,100.88,'EUR',100.88,'2019-01-26 00:17:00.000000',3),
|
||||||
('ETH',-0.8,-0.799,638.9,'EUR',-511.12,'2021-01-01 00:34:00.000000',3);
|
('ETH','S',-0.799,0.001,638.9,'EUR',511.12,'2021-01-01 00:34:00.000000',3);
|
||||||
|
|||||||
Reference in New Issue
Block a user