cadrumo.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 reconciliation: 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 aeat-calculation-aggregation) 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 canonical after-filing reconcile flow owns this comparison.
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
reconciliationReconciliation 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.
The canonical per-casilla divergence carrier. A surface needing to say “this casilla changed” reuses this rather than declaring its own record – a weaker carrier holding only ids, without the values or the kind, was added and reverted once already.
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:
data (Any)
- 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'))[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. THE REGISTRY IS THE AUTHORITY FOR THIS VALUE and publishes it per revision: resolve it withsnapshot.verification_policy().toleranceand pass it. The default is exact equality rather than a cent because the registry’s own schema default is0.00and its policy fold takes the STRICTEST tolerance across a revision’s expectations — so a caller that omits this argument gets the strictest reading rather than a more permissive one it never chose. A revision genuinely rounding to the cent declares that, and passing its published value is what honours it.
- 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.