aeat.application.modelo._reconcile_casilla module¶
Casilla-level divergence detection between a computed revision and a filed declaration.
detect_casilla_divergences is the typed, pure comparison primitive this
module contributes to _reconcile: given the
canonical revision.casilla_values a work unit already persisted (the same
values the calculate path, the result summary, and the export surface render,
per one-aggregation-path-pull-equals-calculate) and the per-casilla values a
filed declaration printed, it classifies every disagreement into one of three
closed CasillaDivergenceKind categories — value_mismatch (both
sides declare the casilla but the amounts disagree beyond tolerance),
missing_in_filed (the computed revision declares the casilla but the filed
declaration omitted it), and extra_in_filed (the filed declaration prints a
casilla the computed revision never resolved a value for). The comparison is
scoped to the registry’s own reconciliation policy
(verification_policy())
so the compared set is declared registry data, never an ad hoc casilla list —
the same scoping verify_declaracion() already
applies to printed-vs-computed comparisons before a filing, kept here for the
after-filing reconcile use.
This module is intentionally free of any PDF-parsing, work-unit, or
bucket-event dependency: it is a pure function over two {casilla_id: Decimal}
mappings plus a tolerance, so it can be tested and reused without a persisted
work unit, a registry snapshot, or a parsed declaración.
See also
_reconcileReconciliation workflow that loads work-unit state and delegates casilla comparison to this pure primitive.
CalculationRevisionPersisted computed revision whose
casilla_valuesare compared.RegistryVerificationPolicyRegistry-declared scope and tolerance used before divergences are surfaced.
ExtractedCasillaParsed declaration row shape that feeds the filed-value mapping.
CasillaDivergenceTyped row returned for each surfaced disagreement.
CasillaDivergenceKindClosed divergence taxonomy emitted by the comparison.
detect_casilla_divergences()Pure comparison entry point exported by this module.
- class CasillaDivergenceKind(*values)[source]¶
Bases:
StrEnumClosed category for one
CasillaDivergence.VALUE_MISMATCH— both the computed revision and the filed declaration declare the casilla but the printed amount diverges from the computed amount beyond tolerance.MISSING_IN_FILED— the computed revision resolved a value for the casilla but the filed declaration did not print it.EXTRA_IN_FILED— the filed declaration printed a casilla the computed revision never resolved a value for.- VALUE_MISMATCH¶
- MISSING_IN_FILED¶
- EXTRA_IN_FILED¶
- class CasillaDivergence(**data)[source]¶
Bases:
BaseModelOne disagreement between a computed revision and a filed declaration.
computed_value/filed_valueareNoneexactly when the corresponding side did not carry a value forcasilla_id(aMISSING_IN_FILEDdivergence carriesfiled_value=None; anEXTRA_IN_FILEDdivergence carriescomputed_value=None).deltais the signedfiled_value - computed_valuewhen both sides carry a value, otherwiseNone— there is no meaningful delta when one side is absent.- Parameters:
casilla_id (CasillaId)
kind (CasillaDivergenceKind)
computed_value (Decimal | None)
filed_value (Decimal | None)
delta (Decimal | None)
- casilla_id: CasillaId¶
- kind: CasillaDivergenceKind¶
- computed_value: Decimal | None¶
- filed_value: Decimal | None¶
- delta: Decimal | None¶
- detect_casilla_divergences(*, computed, filed, scope=None, tolerance=Decimal('0.01'))[source]¶
Classify every casilla-level disagreement between
computedandfiled.- Parameters:
computed (
Mapping[TypeAliasType,Decimal]) – Canonical{casilla_id: value}read from the persistedCalculationRevision(revision.casilla_values).filed (
Mapping[TypeAliasType,Decimal]) –{casilla_id: value}printed on the filed declaration, decoded from the declaration parser’sExtractedCasillarows.scope (
Mapping[TypeAliasType,object] |None) – Optional casilla-id-to-anything mapping restricting comparison to its keys (typically the registry’sverification_policy()computed_casilla_ids). When supplied, bothcomputedandfiledare filtered to this key set before comparison, so a casilla the registry does not reconcile never surfaces a divergence. When omitted, every casilla id present on either side is compared (the union of both key sets).tolerance (
Decimal) – Maximum absolute delta (in the modelo’s currency, typically EUR) that does not surface aVALUE_MISMATCH. Defaults to one cent, matching the registry’s typical rounding tolerance.
- Return type:
- Returns:
A tuple of
CasillaDivergencerows, one per casilla id that diverges, ordered by ascendingcasilla_idfor deterministic output. Empty when every compared casilla agrees within tolerance.