Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 3, 20:45 UTC
source-data-cleanup
ADR-018 — Persistent statements and drill-down lineage (Phase 1)
- Status: Accepted (Phase 1 vertical slice)
- Date: 2026-12-03
- Booklet: §15 Phase 1, D1/D2 (year continuity, drill-down to file/sheet/row)
Context
Phase 0 delivered the domain, LedgerBalance, mappings, notes and the
FinancialStatement/StatementLine models, but no service that turns imported
balances + mappings into persisted, versioned, auditable statements with a
traceable lineage back to the source file/sheet/row.
Decision
Statement build
services/statement_build.build_statements(session, year_id, statement_types):
- Reads the latest import version of
LedgerBalancefor the year. - Reads active
MappingRule(account_code → note) andNoteDefinition(configuration_jsoncarriesstatementandsection). - Aggregates exact integer-rial closing balances per note, applies the display
sign policy (ADR-013: debit-positive closing; display = sign × closing), and
persists a new
FinancialStatementversion with orderedStatementLinerows (mapped_totalin Rial,target_note_idset). - Only Draft years may build; Approved/Locked are blocked by the D-07 triggers.
- Each build creates a new version (never mutates a prior snapshot).
Display sign policy (single source for the persistent engine)
| Statement | Section | sign |
|---|---|---|
| BS | Assets | +1 |
| BS | Liabilities | −1 |
| BS | Equity | −1 |
| IS | Revenue | −1 |
| IS | Expenses | +1 |
Phase 1 renders BS/IS; CF/EQ are deferred to Phase 4.
Drill-down lineage (D2)
drill_down(session, statement_line_id) returns the full chain:
StatementLine → NoteDefinition → MappingRule(s) → LedgerBalance row(s) →
SourceDocument (filename + SHA-256) + source_sheet + source_row. Every statement
total is therefore traceable to the exact source file, sheet and row.
Consequences
- Statements are persisted, versioned, year-isolated and immutable once locked.
- Any figure can be audited down to the originating ledger row.
- The in-memory Pilot workbench remains the interactive editor; this persistent engine is the audited system of record.
Dependencies
python-multipartis required by FastAPI to parsemultipart/form-datafor the ledger and mapping workbook uploads (UploadFile/File). It is the standard FastAPI file-upload dependency, pinned>=0.0.18,<1inbackend/pyproject.toml. No other runtime dependency was added for the statement slice; Excel I/O uses the already-requiredopenpyxl(ADR-017).
Rejected alternatives
- Storing drill-down as a denormalized blob on StatementLine: loses the live join to source and duplicates data; the relational chain is authoritative.