Convert a journal through the account's currency

JA
7d ago
+150-14

Updated 2026-11-20 (head da486e6b6). The two foreign-journal tests now pin which day's rate the second conversion step reads (wrong day: 560 instead of 500, and 720 instead of 562.5), and the class header says how a journal in another currency converts.

Part of #4078 (part 3, returns engine)

Part of #3494

What: a journalled position priced in a foreign currency converts through the account's currency at the holding row's date, then to the family's at the previous day's rate, the two steps Balance::SyncCache takes and an ordinary flow already takes (entry_fx → fx).
Why: journal_fx, journal_prior_fx and carry_fx converted in one step at date - 1, so a foreign journal was valued off by a day's FX move: the returns engine read a different amount from the one the balance moved.
Start reading: the three FX laterals in app/models/portfolio/daily_returns.rb.
Key tests (test/models/portfolio/daily_returns_test.rb):

  • "a journal priced in a foreign currency converts at the holding's own date" (600, the amount the balance moved; the one-step figure was 550)
  • "a journalled foreign position with no rate into the account's currency is flagged"

Behaviour change: none for users. In the model, a foreign journal's value moves to the amount the balance moved, and the performance cache version moves to v12 so returns cached with the one-step conversion are not served after deploy.

Split from #5285 on 2026-11-20 (same commit, unchanged; the cache bump that covered this and the next PR is split in two).
Stack: 12 of 13, on #5297 (GitHub's stacks only take new PRs on top). Merge order: … → #5094 → #5285 → #5296 → #5297 → this PR → #5396. Nothing below reads the FX change.
Fork pre-flight: jaysbeekay/sure#875. Same branch, same commits: up/portfolio-journal-fx-v3 is at the same head in both repositories.

Evidence
  • Fail-first. The FX tests read the one-step figures (550, -550) before the change; the rate-flag test read Expected false to be truthy.
  • Mutation. Each FX step and its date broken on its own is caught; so is the cache version.
  • Tests. Full suite on the stack top: 0 failures; the 8 errors are ReleaseNotesWorkflowTest, no node in the test image.
  • Blast radius. The laterals are read by journal_value_sql, carried_journals_by_date and the rate-missing and unpriced conditions. A rate missing at either step is NULL and still flags. income_by_security does not read them.

Summary by CodeRabbit

  • Bug Fixes
    • Improved portfolio valuation for foreign-currency journal entries by converting through the account currency before converting to the family currency.
    • Applied the conversion to current holdings, unpriced outbound journals, and journals carried forward until a priced day.
    • Missing exchange rates now flag affected days, including internal transfers. Contribution-rate warnings remain limited to external journal flows.
    • Portfolio performance results now reflect the corrected currency conversions.