Derive the lot cost from the kroner that left the account only

This commit is contained in:
ai-bot committed 2026-11-15 10:39:50 +00:00
1 parent 72bea053aa
commit 2840767c3a
1 file changed
+4 -7
+4 -7
View File
@@ -189,22 +189,19 @@ def create_lots_for(tx, conn=None):
created = [] created = []
tx_type = tx["type"] tx_type = tx["type"]
fee_sats = tx["fee_sats"] or 0 fee_sats = tx["fee_sats"] or 0
fee_ore = tx["fee_ore"] or 0
if tx_type == "trade" and tx["leg_in_sats"]: if tx_type == "trade" and tx["leg_in_sats"]:
sats = tx["leg_in_sats"] - fee_sats sats = tx["leg_in_sats"] - fee_sats
# The NOK that left the account. docs/spec.md section 5.1 says # The kroner that left the account (docs/spec.md section 5.1).
# leg_in_ore, but a leg carries one currency only (the CHECK of
# section 4), so a buy keeps it on leg_out_ore.
nok_paid = tx["leg_out_ore"] nok_paid = tx["leg_out_ore"]
if nok_paid is None: if nok_paid is None:
nok_paid = tx["leg_in_ore"] nok_paid = tx["leg_in_ore"]
cost_ore = (nok_paid or 0) + fee_ore cost_ore = nok_paid or 0
elif tx_type == "income" and tx["leg_in_sats"]: elif tx_type == "income" and tx["leg_in_sats"]:
sats = tx["leg_in_sats"] - fee_sats sats = tx["leg_in_sats"] - fee_sats
cost_ore = max((tx["value_ore"] or 0) - fee_ore, 0) cost_ore = tx["value_ore"] or 0
elif tx_type == "gift_received" and tx["leg_in_sats"]: elif tx_type == "gift_received" and tx["leg_in_sats"]:
sats = tx["leg_in_sats"] - fee_sats sats = tx["leg_in_sats"] - fee_sats
cost_ore = (tx["value_ore"] or 0) + fee_ore cost_ore = tx["value_ore"] or 0
else: else:
return created return created
if sats > 0: if sats > 0: