cadrumo.application.modelo._reconcile_population module

Population scoping for casilla reconciliation against a filed declaration.

detect_casilla_divergences() is a pure comparison and takes no view on whether the two sides are worth comparing. Reconciling a freshly onboarded profile against a pulled AEAT filing is the case where that matters: the local calculation computes zero nearly everywhere, so every reconciled casilla diverges and the operator learns nothing except that the bucket is empty. This module supplies the missing predicate — which casillas of a persisted CalculationRevision carry enough locally-sourced input that a divergence means genuine disagreement rather than emptiness — as a scope the existing comparison already accepts, so no second differ is created.

The predicate is evaluated per casilla, not per revision. A revision that supplied one figure out of forty has one thing to say and thirty-nine it does not, and a whole-revision gate would either silence the one or surface the thirty-nine.

WHAT COUNTS AS POPULATION, and why the list is shorter than it looks. A leaf of a casilla’s input closure is independent evidence when the operator supplied the casilla directly, when the operator overrode the binding, when the binding reads declared census facts, or when the binding is bucket-local and the revision actually consumed ledger transactions. Carry bindings (PREVIOUS_FILING, RELATION_PREFILL) and relation references never count, because their values originate in the same filed-observation store the comparison’s filed side is read from: counting them would let the scope be satisfied by the very figures under comparison.

WHAT THIS DELIBERATELY DOES NOT CATCH. A taxpayer whose true figure is non-zero and who supplied nothing leaves the casilla unpopulated, so no divergence is raised and a real under-declaration goes unreported on this channel. That is a false-negative bias, chosen because the alternative fires on every casilla of every empty bucket, which is the alert fatigue that trains an operator to ignore the channel. It must not be read as coverage of the absent-input case, which needs a different signal. Separately, clause four approximates “the bucket holds evidence” with “this revision consumed ledger transactions”, so a bucket populated only with invoices and no ledger transactions scores as empty — again a false negative, and again the safe direction.

See also

detect_casilla_divergences()

The pure comparison this scope is passed to.

CalculationRevision

Persisted revision whose supplied inputs are read.

ModeloRevision

Registry revision supplying the formula graph walked here.

BindingSourceKind

Canonical source taxonomy separating carry bindings from evidence.

class CasillaPopulationScope(**data)[source]

Bases: BaseModel

Which casillas of one persisted revision are worth reconciling.

comparable_casilla_ids is the scope to pass to detect_casilla_divergences(); unpopulated_casilla_ids is its complement over the same candidate set and is carried so a caller can report what was withheld rather than silently narrowing. The three supplied_* fields record the evidence the verdict rested on, so a scope that surprises an operator can be explained without re-deriving it.

Parameters:

data (Any)

comparable_casilla_ids: tuple[CasillaId, ...]
unpopulated_casilla_ids: tuple[CasillaId, ...]
supplied_input_casilla_ids: tuple[CasillaId, ...]
supplied_binding_ids: tuple[BindingId, ...]
ledger_contributed: bool
property divergence_scope: dict[CasillaId, None]

Return comparable_casilla_ids in the mapping shape the comparison takes.

property is_empty: bool

Whether no casilla is comparable, i.e. the local calculation says nothing.

resolve_casilla_population_scope(*, registry_revision, calculation)[source]

Resolve which of registry_revision’s casillas calculation can speak to.

Parameters:
  • registry_revision (ModeloRevision) – The law-resolved ModeloRevision supplying the formula graph, the casilla input kinds and the binding definitions. Resolve it from (modelo, filing_year, period) through the registry authority; never from a stored revision id.

  • calculation (CalculationRevision) – The persisted CalculationRevision whose supplied inputs, binding overrides and ledger contribution decide population.

Return type:

CasillaPopulationScope

Returns:

The CasillaPopulationScope. comparable_casilla_ids is empty exactly when the revision supplied no independent evidence anywhere, so an untouched bucket reconciles to no divergences at all.