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:

str

Parameters:

transaction (Transaction)

compute_ledger_filing_snapshot(*, source_transaction_ids, catalogue, captured_at)[source]

Capture an immutable LedgerFilingSnapshot over 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:
Return type:

LedgerFilingSnapshot

compute_ledger_filing_evidence(*, source_transaction_ids, catalogue, snapshot_fingerprint, captured_at, legal_refs, source_refs, manual_entries=())[source]

Capture the bundled LedgerFilingEvidence fact basis behind one filing revision.

Projects every contributor in source_transaction_ids present in the catalogue into a typed LedgerEvidenceRow, binding the bundle to the revision’s snapshot_fingerprint. manual_entries carries the operator-entered fact basis (casilla inputs / binding overrides) that has no contributing ledger row. Contributor ids absent from the catalogue are skipped (mirroring compute_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 live TransactionCatalogue.

  • 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:

LedgerFilingEvidence

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 ManualFactBasisEntry entries.

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.

Return type:

tuple[ManualFactBasisEntry, ...]

Parameters:
assert_evidence_covers_snapshot(snapshot, evidence)[source]

Raise when bundled evidence omits or invents fingerprinted contributors.

Return type:

None

Parameters:
evaluate_ledger_filing_staleness(snapshot, catalogue)[source]

Compare a filed snapshot against the current ledger state, returning a LedgerFilingStalenessVerdict.

Parameters:
Return type:

LedgerFilingStalenessVerdict

stale_filed_revisions(*, revisions, catalogue)[source]

Return finalized snapshot-backed revisions whose ledger drifted.

Each item pairs a CalculationRevision with its LedgerFilingStalenessVerdict. Scans verified/filed revisions carrying a ledger_filing_snapshot and re-evaluates each against the live catalogue. A revision with no snapshot or a non-finalized state is skipped. Pure given its inputs.

Parameters:
Return type:

tuple[tuple[CalculationRevision, LedgerFilingStalenessVerdict], ...]