Keep a split transaction's activity label on its parts
Closes jaysbeekay/sure#788
Upstream pre-flight. Branch up/investment-totals-split-income: two commits on upstream main 00d177cb0, then a2537ea19, a merge of upstream main 6aa8cf218. The merge keeps both filters in InvestmentFlowStatement#period_totals (split parents left out, plus we-promise/sure#5377's account_id filter); db/schema.rb takes upstream's later version, and the migration keeps its 20261119090000 timestamp.
Upstream issue: we-promise/sure#5498
Upstream PR: we-promise/sure#5507 (draft), same branch, same commit (a2537ea19).
Full unit suite on a2537ea19 (2026-11-21): 18,151 runs, 0 failures; the 8 errors are ReleaseNotesWorkflowTest (no node).
Problem
Splitting a Transaction labelled Dividend or Interest removed it from the investment totals. Entry#split! excluded the parent and gave the parts no investment_activity_label, and InvestmentStatement::Totals reads only non-excluded, labelled rows, so it counted neither. The mirror image hit the income statement: a split Sweep In, Sweep Out, Transfer or Exchange lost its label on the parts, so they counted as income or spending.
What changed
Option B from the issue's Triage Plan, plus the backfill (owner, 2026-11-16).
app/models/entry.rb#split!: each part getsinvestment_activity_label: entryable.try(:investment_activity_label)besidekind:. A part can still be relabelled afterwards.db/migrate/20261119090000_backfill_split_part_activity_labels.rb: data migration, no schema change. Gives each existing unlabelled part its Transaction parent's label, unless the part's label is inlocked_attributes.downis a no-op.db/schema.rbversion bumped.app/models/investment_flow_statement.rb#period_totals: leaves split parents out (Entry.excluding_split_parents). Not in the issue's plan; found while checking the blast radius. This reader doesn't filter excluded entries, so it counted a split Contribution's parent and skipped its unlabelled parts. With the parts now labelled it would count the money twice. Leaving split parents out keeps every unsplit entry as before; whether it should skip excluded entries generally is still out of scope, as the issue says.
Tests
| Test | Before the fix |
|---|---|
InvestmentStatementTest "a split Dividend transaction still counts in dividends" | dividends 0 after the split |
| "a split Interest transaction still counts in interest" | interest 0 |
| "a split part relabelled away from Dividend leaves dividends" | 0, expected 60 |
| "a split unlabelled transaction stays out of investment income" | boundary, passes both ways |
IncomeStatementTest "a split Sweep In transaction stays out of income" | Expected: 1000, Actual: 1500 |
EntrySplitTest "split! gives each part the parent's activity label" | Actual: [nil, nil] |
EntrySplitTest "split! leaves the parts unlabelled when the parent has no activity label" | boundary |
InvestmentFlowStatementTest "a split contribution counts once" | 200 with the label copy and no parent guard |
BackfillSplitPartActivityLabelsMigrationTest: backfills, keeps a part's own label, leaves an unlabelled parent's parts, leaves a locked label | fail without the backfill / lock guard |
Mutations, one at a time:
- Drop the label from
split!: 5 failures (entry split, both totals tests, relabel, Sweep In). - Drop the split-parent guard in
InvestmentFlowStatement: "a split contribution counts once" fails. - Skip the backfill: 2 migration tests fail.
- Drop the lock guard: "leaves a part whose label the user locked" fails.
Runs: targeted suites (entry split, investment/income/flow statements, income statement folder, migration, splits controllers web and API, data importer, QIF import, rule split action, flow classifier, reports controller): 715 runs, 0 failures. Full unit suite: 17,546 runs, 0 failures; the 8 errors are ReleaseNotesWorkflowTest (no node in the test image). RuboCop: no offences. Brakeman: 0 warnings.
Blast radius
split!callers:split_once!,resplit!(web and API splits controllers),Rule::ActionExecutor::SplitTransaction,Family::DataImporter#import_split_lines!,QifImport. None passes a label, so each part takes the parent's. The data export carries no labels, so an imported split is consistent with its parent.- Label readers:
InvestmentStatement::TotalsandPortfolio::FlowClassifierskip excluded entries and now see the parts.IncomeStatement::TotalsandDailyExpenseTotalsskip excluded rows and now drop split internal movements.InvestmentFlowStatementis guarded as above. Trade-label readers (Holding,ReportsController,TradesController) are unaffected, since parts are always Transactions.
Overlap check (upstream, any author)
- we-promise/sure#5070 and #5107 (Totals rewrite onto
FlowClassifier) still filterentries.excluded = falseand add no parent fallback or label copy: distinct. Whichever lands first, the other rebases; with this change the parts are labelled, so the rewrite needs no fallback. - we-promise/sure#3506 (draft) moves synced income to Trades: distinct, and manual or other-provider Transactions stay affected.
- we-promise/sure#4467, #3428, #3728, #4966 and the merged #5134 touch
split!without copying the label. #4467 edits the sameTransaction.newblock, so a textual conflict is possible.
Migration note
Data-only migration on transactions, updating unlabelled split parts in one statement. Safe to re-run; its down is a no-op.