Repository: rotki/rotki

Issue:
Ledger Actions ignored in PnL Calculation
## Problem Definition

Some ledger actions are ignored for the "Tax Free PnL" / "Taxable PnL" columns of the profit and loss report.
As far as I have seen, this issue occurs if the asset/currency is EUR or USD, but not if the asset is ETH.

Example to reproduce:
1. Add a manual ledger action, e.g. an expense of 10 USD
2. Ensure that "taxable" is enabled for this ledger action in the settings
3. Generate a profit and loss report for the respective time period
4. The value of the ledger entry can be seen in the "taxable amount" column, but not under "taxable PnL"
5. The value is also not included in the total sum under "overview"
6. Go back to the ledger action and change the asset to ETH
7. Re-generate the PnL report
8. The expense is included in the PnL sum

Is this behavior intended? If not, could it be because no cost basis is evaluated for main currency?

On a side note, the total PnL values calculated for my rotki databases have changed in the last months (significantly, not just rounding errors), although I did not add any actions.
I did not see any entry in the changelog that could cause this. Did the PnL calculation change in the last months?

### System Description

Operating system: Windows 10
App Version: 1.25.3
Frontend Version: 1.25.3
Electron: 18.2.3


Discussion:
> I did not see any entry in the changelog that could cause this. Did the PnL calculation change in the last months?

Yes. We are auto-detecting and actually decoding ethereum transactions now. Which is a constant work in progress and a lot of times needs user intervention as it's hard to auto-detect purpose of everything correctly.
For more questions about this please pop up in our discord: https://discord.gg/aGCxHG7  (have DMs open since there is a captcha)

> Is this behavior intended? If not, could it be because no cost basis is evaluated for main currency?

Good question. The behavior you are describing is reproducable and I can see why.

There is something in the code that forces this if it is a FIAT asset. So USD, EUR, GBP etc.
https://github.com/rotki/rotki/blob/f0ae094d1edf64bf961652d9b58a21f9e18a5c01/rotkehlchen/accounting/pot.py#L215

Looking at the code I suspect it's due to the way the new accounting modules work where trades are broken into asset in, asset out and optional fee. When you buy something with fiat the fiat spending is not a taxable event and probably(?) this is why we had this condition there but it needs to be narrowed down to only those cases.

So it does not catch ledger actions. Let us think and include this in the next release


Resolving patch:
diff --git a/rotkehlchen/accounting/pot.py b/rotkehlchen/accounting/pot.py
--- a/rotkehlchen/accounting/pot.py
+++ b/rotkehlchen/accounting/pot.py
@@ -212,8 +212,8 @@ def add_spend(
         if amount == ZERO:  # do nothing for zero spends
             return ZERO, ZERO
 
-        if asset.is_fiat() and event_type != AccountingEventType.FEE:
-            taxable = False
+        if asset.is_fiat() and event_type == AccountingEventType.TRADE:
+            taxable = False  # for buys with fiat do not count it as taxable
 
         handle_prefork_asset_spends(
             cost_basis=self.cost_basis,


Test patch: