Repository navigation
fix(dividends): restore the 0588 credit for Trade Republic foreign dividends - #432
Conversation
…cy (#96) Trade Republic keeps a US dividend in USD but books its withholding in EUR. The matcher required the same ISIN and currency, so the pair never matched and Casilla 0588 came out 0 for every TR foreign dividend. A second pass now pairs a still-unmatched dividend with a withholding of the same ISIN in another currency, after the unchanged same-currency pass, so every broker that matched before pairs exactly as before. The withholding is valued in its own currency (EUR 1:1), never at the dividend's rate.
TR converts a foreign dividend and credits EUR, so the taxpayer never holds the USD. Each dividend still opened a USD lot that nothing closed: harmless alone, but merged with an IBKR file FIFO consumed those dollars first and moved 1633/1637. The TR parser flags such dividends with CashTransaction.brokerConvertedToBase and extractCashFxEvents skips flagged rows. 0029 is unchanged (gross USD at the ECB rate of the payment date).
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #432 +/- ##
==========================================
+ Coverage 93.07% 93.08% +0.01%
==========================================
Files 63 63
Lines 6840 6856 +16
Branches 2337 2343 +6
==========================================
+ Hits 6366 6382 +16
Misses 391 391
Partials 83 83
🚀 New features to boost your workflow:
|
Problem
Trade Republic credits foreign dividends in EUR. Its export keeps the dividend in USD and the withholding in EUR. Two things went wrong:
The DGT values a dividend at the official rate of the day it is payable (V1024-11) and defers the currency result only «cuando lo recibido sean divisas» (V2466-08, V2422-20). When the broker credits euros, there is no currency to track.
Fix
dividends.ts: a withholding first pairs with a same-currency dividend, exactly as before, so IBKR, Degiro and the rest are unchanged. A dividend still unpaired then takes a withholding of the same ISIN in another currency. The withholding is valued in its own currency: EUR is 1:1, never multiplied by the USD rate.CashTransaction.brokerConvertedToBaseflag. The Trade Republic parser sets it on dividends it credited in EUR, andextractCashFxEventsskips those rows. Casilla 0029 is unchanged: gross USD × ECB rate of the payment date.On a Trade Republic export with two $10 US dividends: 0588 goes from 0.00 to 2.63, 0029 stays 17.82, and the FX trace is empty. Merged with an IBKR file, the FX result now equals IBKR alone.
Tests
13 new tests: engine, parser, and an end-to-end merge with a real IBKR Flex XML. Nine of them fail on the old code. The other four guard existing behaviour, and each one fails against a deliberately wrong version of the fix. Full suite: 2639 passed. Lint and typecheck are clean.
Follow-up, not in this PR: Degiro AutoFX and Trading 212 EUR accounts have the same lot problem.
Refs #96
Summary by CodeRabbit