Record dividends and interest as Trades in investment accounts

Merged
HA
8mo ago
+336-81

Summary

Follow-up to #1246 (closed)

Reworks dividend and interest recording based on feedback from @luckyPipewrench: instead of adding security_id to the transactions table, all investment income is now a Trade.
The account type is the discriminator — investment income is a portfolio event regardless of whether a ticker is attached.

Dividends → Trade, qty: 0, price: 0, security required
Interest → Trade, qty: 0, price: 0, security optional — falls back to a per-account synthetic cash security when none is selected (same approach brokerages use internally for uninvested cash)

Model changes

securities: new kind column ("standard" / "cash") with DB check constraint
Security.cash_for(account) — lazy find-or-create for the synthetic cash security
scope :standard — excludes synthetic securities from all user-facing pickers
transactions table: untouched

UI changes

  • Add dividend as selectable option in new activity modal
  • New dropdown input with account-related securities shown when dividend/interest is chosen
  • Quick edit badge now non-interactive when it's an income trade (changing type after creation creates issues)

Additional notes

  • i18n files included for FR, ES & DE
  • Revelant tests added
  • I tried to keep this PR as lean as possible while still having a functionnal UI

Activity ledger

image

New dividend transaction

image

Summary by CodeRabbit

  • New Features

    • Added Dividend and Interest trade types and synthetic cash securities.
  • Improvements

    • Income trades display absolute amounts and are read-only in quick-edit/show.
    • Trade form/header use localized labels, conditional inputs, and ticker selection for income types.
    • Submitted income amounts are normalized to negative for storage.
  • Bug Fixes

    • Dividend creation requires a security and returns an error when missing.
  • Chores

    • Added security kind with validation/scope; health checks now target standard securities.
  • Tests

    • Added/updated tests for income trades and synthetic cash behavior.