Skip to content

feat(report): add FX method-consistency and deferred-conversion notes#252

Merged
GeiserX merged 1 commit into
mainfrom
feat/fx-method-notes
Jun 20, 2026
Merged

feat(report): add FX method-consistency and deferred-conversion notes#252
GeiserX merged 1 commit into
mainfrom
feat/fx-method-notes

Conversation

@GeiserX

@GeiserX GeiserX commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Summary

Adds two in-app info notes and fixes a stale guide string clarifying how DeclaRenta treats foreign-currency (divisa) gains for foreign-currency stock accounts. Motivated by a community thread where users got contradictory answers (realize-at-purchase vs. defer-to-conversion) for the "I trade US stocks in a USD account and never convert to EUR" case.

DeclaRenta already implements the legally-correct deferral method (carry-basis; Art. 14.2.e LIRPF; DGT V0152-26): buying a stock in USD does not realize an FX gain — only an actual USD→EUR conversion does. The engine is unchanged; this PR closes the communication gaps around it.

Changes

  • report.fx_method_consistency (info, fires when FX disposals exist): explains the divisa gain is deferred until conversion to euros, and warns not to mix methods across years (mixing defer with a realize-at-buy method can double-count or drop carried basis).
  • report.fx_deferred_no_conversion (info, fires when there are 0 FX disposals but the user holds non-EUR STK/FUND/BOND securities): confirms 0 in casillas 1633/1637 is correct, and that IBKR's "realized forex gain" uses the US criterion, not the Spanish one. Scoped so it never fires on EUR-only or crypto-only files.
  • guide_rw.fx_note rewritten in all 5 locales (es, en, ca, eu, gl): the old text wrongly said FX only appears on manual currency trades — false since auto-convert (ISSUE El motor de detección ifFxcon genera operaciones fantasma. #239) and stock round-trips (ISSUE. Las ventas de acciones con plus/minusvalía en FCY no están trasladando efectos a la Divisa #230).

Both notes are severity: "info" (not warnings), consistent with the project's "don't alarm users with non-critical info" posture, and are excluded from the deprecated warnings/messages sync check exactly like the existing report.competitor_reconciliation note.

Testing

  • npm run typecheck, npm run typecheck:tests, npm run lint — clean
  • npm test — relevant suites green: FX integration (carry-basis, trace), generators (36/36 incl. the updated sync test), i18n + web + generators batch (433/433)
  • Updated the legacy should keep warnings and messages in sync test to exclude the two new info-only IDs (same precedent as competitor_reconciliation)

Summary by CodeRabbit

  • New Features

    • Added informational messaging about deferred foreign-currency gains when no conversions occur in the tax year.
  • Documentation

    • Updated translations across multiple languages to clarify that FX gains are recognized for both manual and automatic broker currency conversions (e.g., IBKR AFx/FXCONV).
    • Enhanced messaging to explain method consistency and timing of foreign-exchange gain realization.
  • Tests

    • Updated test assertions to accommodate new informational messages.

Clarify how DeclaRenta handles foreign-currency (divisa) gains for
foreign-currency stock accounts, after a community thread surfaced
contradictory interpretations of the realize-vs-defer question.

- report.fx_method_consistency (info): when FX disposals exist, explain
  the divisa gain is deferred until the currency is converted to euros
  (Art. 14.2.e LIRPF; DGT V0152-26) and warn not to mix methods across
  years, which can double-count or drop carried basis.
- report.fx_deferred_no_conversion (info): when the user holds
  foreign-currency securities (non-EUR STK/FUND/BOND) but made no
  FCY->EUR conversion, confirm that 0 in casillas 1633/1637 is correct
  and that IBKR's "realized forex gain" uses the US criterion, not the
  Spanish one.
- guide_rw.fx_note: rewrite in all 5 locales. The old text wrongly said
  FX only appears on manual currency trades, false since auto-convert
  (#239) and stock round-trips (#230).

Both notes are info severity (not warnings) and excluded from the
deprecated warnings/messages sync check, matching the existing
report.competitor_reconciliation note.
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

generateTaxReport replaces the FX competitor-reconciliation info message with two new conditional messages: fx_method_consistency when FX disposals exist, and fx_deferred_no_conversion when no FX disposals exist but foreign-currency securities are present. Five locale files update guide_rw.fx_note to include automatic broker conversions. The warnings/messages sync test excludes the two new message IDs.

FX Messaging and Localization Update

Layer / File(s) Summary
FX message conditions in generateTaxReport
src/generators/report.ts, tests/generators/report.test.ts
Replaces report.competitor_reconciliation with report.fx_method_consistency when fxDisposals.length > 0; adds report.fx_deferred_no_conversion when no FX disposals exist but STK/FUND/BOND disposals with non-EUR currency are present. Test excludes both new IDs from the warnings/messages count comparison.
guide_rw.fx_note locale updates
src/i18n/locales/en.ts, src/i18n/locales/es.ts, src/i18n/locales/ca.ts, src/i18n/locales/eu.ts, src/i18n/locales/gl.ts
Rewrites the FX note in all five locales to cover automatic broker conversions (e.g., IBKR AFx/FXCONV), not only manual currency trades, and clarifies FX deferral until actual EUR conversion.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • GeiserX/DeclaRenta#123: Expands FX FIFO inputs in generateTaxReport (cash-transaction FX events, lot-driven disposals), directly affecting whether FX disposals exist — the condition this PR's new messages depend on.
  • GeiserX/DeclaRenta#169: Also modifies generateTaxReport to conditionally emit or suppress FX-related user messages based on skipFx and FX disposal presence, the same branching logic touched here.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main changes: adding two FX-related informational notes (method-consistency and deferred-conversion) to the report generator.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/fx-method-notes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.30%. Comparing base (26f13fb) to head (f7158c8).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #252   +/-   ##
=======================================
  Coverage   95.29%   95.30%           
=======================================
  Files          54       54           
  Lines        5185     5192    +7     
  Branches     1736     1739    +3     
=======================================
+ Hits         4941     4948    +7     
  Misses        210      210           
  Partials       34       34           
Files with missing lines Coverage Δ
src/generators/report.ts 96.37% <100.00%> (+0.13%) ⬆️
src/i18n/locales/ca.ts 100.00% <ø> (ø)
src/i18n/locales/en.ts 100.00% <ø> (ø)
src/i18n/locales/es.ts 100.00% <ø> (ø)
src/i18n/locales/eu.ts 100.00% <ø> (ø)
src/i18n/locales/gl.ts 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@GeiserX GeiserX merged commit 232fc43 into main Jun 20, 2026
4 of 5 checks passed
@GeiserX GeiserX deleted the feat/fx-method-notes branch June 20, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant