Add security name to transactions for dividend tracking
Closed
HA
8mo ago+336+336+012345678901234567890123456789-13-13-01234567890123456789
Summary
Allow Interest and Dividends transactions to be linked to a security in the investment ledger.
This sets the foundation for future dividend-by-security reporting.
Also added 'Dividend' in the activity creation form dropdown. It simplifies manual dividend entry and seems logical to have next to 'Interest'
Details
- Adds a
security_idFK on the transactions table so dividend (and other) transactions can be linked to a specific security - Adds a "Dividend" type to the trade creation form with an optional security picker populated from the account's current holdings
- Auto-names dividend entries based on the linked security (e.g. "Dividend: AAPL") and keeps the name in sync when the security or activity label changes
- Shows a security dropdown on the transaction detail view for investment/crypto accounts
- Migration:
add_reference :transactions, :security(nullable UUID FK with index)
Model changes:
- Transaction gains
belongs_to :security, optional: true - Security gains
has_many :transactions, dependent: :nullify Account#available_securities— new helper that queries securities held by the account (DB-level distinct + order)Security#name_with_ticker— display helper for dropdowns
Controller changes:
Trade::CreateFormhandles the new dividend type, creating a Transaction (not a Trade) with the Dividend activity label and optional securityTransactionsController#updateauto-syncs the entry name when the activity label or security changes on a dividend transaction
i18n: Four locales (en/de/es/fr) updated for both trade form and transaction detail view.
Summary by CodeRabbit
-
New Features
- Create dividend transactions with optional security selection; entry names auto-format with linked security ticker
- Transactions can be linked to securities (optional); transaction details show a security chooser for investment/crypto accounts and disable name editing for Dividend/Interest
- Trade forms: security selector added and trade type labels localized; accounts expose available securities and securities show ticker with name
-
Tests
- Added tests for dividend creation, updates, and transaction–security associations