Group the allocation by what the classification slices write
Slice 3.4 of #122 (IP3 — classification and allocation). Triage plan: #122 comment.
Fork-only. 3.3 onward is UI, which under the revised delivery model in #118 stays on fork main behind the preview gate rather than going upstream as it is built.
What this is
The allocation section already groups four ways — security account currency kind — and none of them can group by anything #192 (3.2) and #193 (3.1) write. Until this lands the classification columns have no consumer, so nobody can see whether what those slices write is right.
Four groupings are added: asset class, sub-class, sector, region. The donut, segmented control, colour palette, weight arithmetic and table all keep working — this extends a working section rather than replacing it.
The Unclassified bucket is load-bearing, not cosmetic
Portfolio::SectionRegistry gates the section on allocation_segments.any?. A grouping returning [] would hide the whole allocation section rather than show an empty one.
So without UNCLASSIFIED, a portfolio of unclassified securities loses the section instead of being told it has nothing classified yet — and that is every portfolio until #192 and #193 merge. Which is also what this looks like today: one Unclassified segment carrying the full value. That is correct behaviour, and a test asserts it directly rather than leaving it to be discovered.
Where the cash goes differs per grouping
Cash is not a holding — it sits on the account, and allocation_by_currency/allocation_by_kind already add each account's positive cash separately. Every new grouping has to say where it goes, and the honest answer is not the same for all four:
| grouping | cash lands in | why |
|---|---|---|
| asset class | liquidity | a cash balance is liquidity |
| sub-class | cash | likewise |
| sector | Unclassified | cash has no sector |
| region | Unclassified | cash has no region |
The obvious implementation puts it in liquidity everywhere; the test pins both directions, because inventing a sector for cash puts an exposure in the chart the family does not have.
The drill-down
Asset class → sub-class → holdings, as a <details> disclosure — native HTML per convention 3, not a new Stimulus controller.
Only that ladder nests. A sector has no sub-sector here, so sector, region, currency and account render flat rather than being dressed up as something that opens. Expanding Liquidity shows the account cash, or the children would contradict the parent row's amount.
Blast radius
ALLOCATION_GROUPINGSis a whitelist, not just a list.PortfoliosController:21readsparams[:by].presence_in(ALLOCATION_GROUPINGS), so a new entry is reachable by URL the moment it is in the constant. The locale keys land in the same commit for that reason, and a controller test asserts each new grouping renders rather than 500s.allocation_segment_namereturnedsegment.nameraw for everything butkind. The new groupings carry keys (equity,north_america,unclassified), so each is translated — withdefault:fallback, sincesectoris provider free text with no key and should show the value rather than "translation missing".
Evidence
- 10 tests — per-grouping amounts and weights, the Unclassified bucket on an entirely unclassified portfolio, cash placement both ways, a partly classified portfolio whose weights still sum to 100, the drill-down at both levels, Liquidity expanding to its cash, and the flat groupings returning no children.
- 4 mutations, all caught: Unclassified fallback removed, cash given a sector, a grouping dropped from the constant, the asset-class cash bucket removed.
- 309 runs / 1293 assertions across statement, controller, portfolio models and helpers — 0 failures.
- Full suite: 9901 runs, 41229 assertions, 0 failures, 1 error — the
PG::ConnectionBadinRecurringTransaction::PipelineTest, which is issue #168 and reproduces on branches carrying none of these changes. - Rubocop, erb_lint and Brakeman clean.
enanddelocale keys.
Leaves out
3.5 (tags), 3.6 (AI proposals), 3.7 (fund look-through), and any change to how weights are computed. Sorting stays by amount, largest first, rather than adding per-column sort to a section that has never had it.