fix an issue with BCH, because we bought for 0 Euro when it was split from BTC

This commit is contained in:
2021-01-08 07:13:00 +01:00
parent 22f21e8f36
commit 5db3c58505
+4 -4
View File
@@ -25,10 +25,10 @@ class Calc:
out["crypto"] = crypto
with connection.cursor() as cursor:
sql = """SELECT SUM(amount_after_fee) as after_fee, SUM(amount) as amount FROM `transaction` WHERE amount >= 0 and crypto_currency=%s and owner_id=%s"""
sql = """SELECT SUM(amount_after_fee) as after_fee, SUM(amount) as amount FROM `transaction` WHERE amount_after_fee > 0 and crypto_currency=%s and owner_id=%s"""
cursor.execute(sql, [crypto, userid])
bought = cursor.fetchone()
if bought[1]:
if bought[0]:
out["bought"] = bought[1]
total_investment += Decimal(bought[1])
amount_kept += Decimal(bought[0])
@@ -36,10 +36,10 @@ class Calc:
out["bought"] = None
with connection.cursor() as cursor:
sql = """SELECT SUM(amount_before_fee) as before_fee, SUM(amount) as amount FROM `transaction` WHERE amount < 0 and crypto_currency=%s and owner_id=%s"""
sql = """SELECT SUM(amount_before_fee) as before_fee, SUM(amount) as amount 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[1]:
if sold[0]:
out["sold"] = sold[1]
total_investment += Decimal(sold[1])
amount_kept += Decimal(sold[0])