Spike: credit card EMI on loan layer and Bills installments
DA
19d ago+3896+3896+0123456789012345678901234567890123456789-111-111-012345678901234567890123456789
Summary
This spike models a credit-card EMI as a Bills installment plan using Sure's existing loan amortization engine and Bills machinery. It does not add a second amortization engine, new transaction kinds, future-dated entries, or a parallel Loan model.
- Plan terms live on the Bills installment series.
- A manual credit-card purchase becomes the plan source; it leaves the budget and balance and is locked while the plan owns it.
- Confirmed full charges split into principal and interest through the existing split engine.
- Future reserves stay whole; only confirmed charges split.
- Terms are editable only while the plan is active, has no allocation, and has no skipped or missed occurrence.
- Synced and read-only accounts are refused.
Review fixes
- Plan-owned purchases are protected across the UI, web/API split, transfer matching, mark-recurring, bulk update/delete, rules, enrichment, category merge and category replacement.
- The financed split runs inside the allocation transaction, so a failed split rolls the payment back instead of leaving a confirmed charge whole.
- Unsplit failures also propagate, so a failed unsplit aborts the unallocation instead of leaving the payment unlinked.
- Split, transfer-match and duplicate-merge lock Transaction rows before Entry rows, removing the split/transfer deadlock.
- Release locks the plan and open occurrences before checking allocations; ended plans cannot receive matches.
- Release callbacks run only on the transition to ended and preserve later manual exclusions.
- Unlinking the last payment, rejecting the last confirmed payment and rejecting the last suggestion all release an ended plan's purchase.
- The enrichment guard covers entryables, so tag and investment-label rules cannot mutate a plan-owned purchase.
- Category replacement moves only plans still using the replaced category.
- Orphan repair rechecks allocation capacity and ignores excluded entries.
- Bayes evaluation keeps plan purchases out of its scored test set.
- Transfer matching locks both legs and rechecks plan ownership before writing.
- Bulk update/delete report locked rows.
- Terms parse as base 10.
- API split rejects plan-owned transactions on POST, PATCH and DELETE, and checks account permission before ownership.
schema.rbanddocs/api/openapi.yamlregenerated.
Validation
- Full unit suite:
13244 runs, 60883 assertions, 0 failures, 0 errors, 36 skips - Focused plan/transfer/merge tests:
108 runs, 322 assertions, 0 failures - Installment-plan system test:
1 run, 6 assertions, 0 failures - RuboCop, ERB lint, Biome lint: clean
- Brakeman: no warnings
Migration
db/migrate/20261022120000_add_financing_terms_to_recurring_transactions.rb
https://github.com/user-attachments/assets/1d690997-885d-4539-8969-5be1bf1aa722
Summary by CodeRabbit
- New Features
- Create installment plans for eligible credit-card purchases, preview estimated payments, and edit plan terms before the first payment.
- View installment dates, principal and interest breakdowns, and total interest in bill details.
- Updates
- Purchases owned by installment plans are protected from conflicting manual edits, automated changes, deletion, splitting, and transfer matching. Bulk actions report when selected purchases cannot be changed.
- Eligible confirmed plan charges are split into principal and interest; charged plans are ended rather than deleted.
- Split-child transactions no longer appear as recurring-payment candidates.