Backing transaction ledger: replace applied field with Postings #19
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
Replace the hand-edited
appliedcolumn onmonth_entrywith a backing ledger of individual transactions (Postings). Applied becomes a derived sum. Planned becomes click-to-edit instead of an always-on input. Some entries will have one posting per month (mortgage); others will have many (groceries).Schema
New table
posting:Model class
Posting. UI and docs continue to call them "transactions"; the schema/ORM names use the accounting-correct term.Drop
month_entry.appliedApplied is computed as
SUM(amount)over the entry's postings. No stored column.Migration (single alembic revision)
postingtable.month_entrywith a non-zero applied value, insert one "opening balance" posting:occurred_on = month.activated_at OR month.created_atamount = month_entry.applieddescription = "opening balance"payee = NULLappliedcolumn frommonth_entry.Closed months go through the same migration path; their totals stay correct via the opening-balance posting.
Service layer
month_service.add_posting(db, month, entry, date, amount, description=None, payee=None) -> Postingmonth_service.update_posting(db, month, posting_id, **fields) -> Posting | Nonemonth_service.delete_posting(db, month, posting_id) -> boolentry.appliedbecomes a computed property / dataclass field sourced from summing postings.update_month_entryno longer acceptsapplied; the keyword is removed.ensure_editable(month)still gates every mutation.Routes
Each returns the updated section partial + OOB swaps for zero widget and group totals (same pattern as existing mutations).
ensure_editableguard applies.POST /month/{ym}/entries/{id}loses theappliedform field but keeps name / planned / notes.UI
$412.33 · 7 txnswhen postings exist.occurred_on DESCwith columns date / description / payee / amount / delete. Inline add form at the bottom with date (defaults to today), amount, optional description, optional payee, submit.Validation
occurred_on: must parse as ISO date (YYYY-MM-DD); free-form, NOT constrained to the month for now.amount: any decimal, negative allowed. Zero also allowed.Deviation state
Adding / editing / deleting postings does NOT flip the row's deviation state. Deviation tracks drift from the snapshot (name, planned), not the flow of transactions.
Zero amount, progress bars, group totals
All keep their current semantics, reading through the computed applied. Close gate stays; balanced at
$0.00 applied zerostill required to close.Acceptance criteria
posting, seeds opening-balance postings, dropsmonth_entry.appliedPostingmodel with cascade frommonth_entryappliedOut of scope
payee