aeat.application.aggregation._ledger_filing_snapshot module¶
Capture and staleness for the modelo filing ledger snapshot.
Used by: application.modelo._work_lifecycle for revision staleness checks,
application.evidence for audit bundle generation.
The pure records live in domain.modelos._ledger_filing_snapshot.
This application module holds the Transaction-aware halves:
computing a contributor’s content fingerprint from the live
TransactionCatalogue, building a
LedgerFilingSnapshot for a
CalculationRevision’s source_transaction_ids,
and evaluating drift between a filed snapshot and the current ledger state.
The fingerprint covers exactly the transaction facts that can move a casilla – dates, amount magnitude, currency, direction, business classification and proportionality, the IVA base/rate/amount/category, the spending and IRPF categories, the EU member state, the FX conversion, and the lifecycle state. Cosmetic fields (description, counterparty, notes) are deliberately excluded so staleness fires on material change, not on a relabel.
This module uses
LedgerFilingStalenessVerdict
for drift evaluation.
- row_fingerprint(transaction)[source]¶
Return the SHA-256 content fingerprint of one transaction’s tax facts.
- Return type:
- Parameters:
transaction (Transaction)
- compute_ledger_filing_snapshot(*, source_transaction_ids, catalogue, captured_at)[source]¶
Capture an immutable
LedgerFilingSnapshotover a revision’s contributing rows.Contributor ids absent from the catalogue are skipped (a snapshot records the rows that exist at capture time); an empty contributor set yields a valid empty snapshot, which is the uniform shape for non-ledger modelos.
- Parameters:
source_transaction_ids (
Iterable[str]) – Contributor identifiers.catalogue (
TransactionCatalogue) – The liveTransactionCatalogue.captured_at (
datetime) – Captured timestamp.
- Return type:
- compute_ledger_filing_evidence(*, source_transaction_ids, catalogue, snapshot_fingerprint, captured_at, legal_refs, source_refs, manual_entries=())[source]¶
Capture the bundled
LedgerFilingEvidencefact basis behind one filing revision.Projects every contributor in
source_transaction_idspresent in the catalogue into a typedLedgerEvidenceRow, binding the bundle to the revision’ssnapshot_fingerprint.manual_entriescarries the operator-entered fact basis (casilla inputs / binding overrides) that has no contributing ledger row. Contributor ids absent from the catalogue are skipped (mirroringcompute_ledger_filing_snapshot()); the caller’s no-silent-omission guard cross-checks the evidence set against the fingerprint set.- Parameters:
source_transaction_ids (
Iterable[str]) – Contributor identifiers.catalogue (
TransactionCatalogue) – The liveTransactionCatalogue.snapshot_fingerprint (
str) – The fingerprinted snapshot identifier.captured_at (
datetime) – Captured timestamp.legal_refs (
Iterable[TypeAliasType]) – Registry legal references grounding this evidence bundle.source_refs (
Iterable[TypeAliasType]) – Official source references grounding this evidence bundle.manual_entries (
tuple[ManualFactBasisEntry,...]) – The manual entries basis.
- Return type:
- project_manual_fact_basis_entries(input_values_by_casilla_id, *, legal_refs_by_casilla_id, source_refs_by_casilla_id)[source]¶
Project operator-entered casilla inputs into
ManualFactBasisEntryentries.The calculation revision stores caller-supplied casilla inputs as rendered strings. Non-empty values are part of the evidence bundle because no ledger row explains them.
- assert_evidence_covers_snapshot(snapshot, evidence)[source]¶
Raise when bundled evidence omits or invents fingerprinted contributors.
- Return type:
- Parameters:
snapshot (LedgerFilingSnapshot)
evidence (LedgerFilingEvidence)
- evaluate_ledger_filing_staleness(snapshot, catalogue)[source]¶
Compare a filed snapshot against the current ledger state, returning a
LedgerFilingStalenessVerdict.- Parameters:
snapshot (
LedgerFilingSnapshot) – The filed ledger snapshot.catalogue (
TransactionCatalogue) – The liveTransactionCatalogue.
- Return type:
- stale_filed_revisions(*, revisions, catalogue)[source]¶
Return finalized snapshot-backed revisions whose ledger drifted.
Each item pairs a
CalculationRevisionwith itsLedgerFilingStalenessVerdict. Scans verified/filed revisions carrying aledger_filing_snapshotand re-evaluates each against the live catalogue. A revision with no snapshot or a non-finalized state is skipped. Pure given its inputs.- Parameters:
revisions (
Mapping[str,CalculationRevision]) – A mapping ofCalculationRevisionfiles.catalogue (
TransactionCatalogue) – The liveTransactionCatalogue.
- Return type:
tuple[tuple[CalculationRevision,LedgerFilingStalenessVerdict],...]