aeat.domain.calculations.registry._withholding_bindings module¶
Withholding row-set binding helpers.
Withholding-source bindings declared on a ModeloRevision are resolved
from per-perceptor withholding observations into scalar values or row outputs.
- class WithholdingObservation(**data)[source]¶
Bases:
BaseModelPer-perceptor retencion / ingreso-a-cuenta observation for modelo 190 / 193.
- Parameters:
- source_id: str¶
- perceptor_tax_id: str¶
- perceptor_legal_name: str¶
- country_code: str¶
- transaction_date: date¶
- clave: RetencionClave¶
- subclave: str¶
- percibido_dinerario: Decimal¶
- percibido_especie: Decimal¶
- retencion_practicada: Decimal¶
- ingreso_a_cuenta: Decimal¶
- class WithholdingObservationRequirement(**data)[source]¶
Bases:
BaseModelWithholding-source slice declared by one or more withholding bindings.
- Parameters:
binding_ids (tuple[BindingId, ...])
claves (tuple[RetencionClave, ...])
- binding_ids: tuple[BindingId, ...]¶
- claves: tuple[RetencionClave, ...]¶
- validate_withholding_binding_selector_shape(binding)[source]¶
Validate withholding selector shape and fact/op invariants for snapshot build.
- Return type:
- Parameters:
binding (DataBindingDefinition)
- withholding_binding_requirements(revision)[source]¶
Return
WithholdingObservationRequirementslices needed byrevision’s withholding bindings.The
ModeloRevisionis introspected for withholding bindings and grouped by the clave filters their selectors declare.- Return type:
- Parameters:
revision (ModeloRevision)
- resolve_withholding_binding_values(revision, observations)[source]¶
Resolve scalar withholding-source bindings into Decimal aggregates.
The
ModeloRevisioncontributes scalar withholding bindings; row producer bindings are handled byresolve_withholding_binding_row_values.- Return type:
- Parameters:
revision (ModeloRevision)
observations (Iterable[WithholdingObservation])
- resolve_withholding_binding_row_values(revision, observations)[source]¶
Resolve row-producer withholding bindings into per-row indexed values.
The
ModeloRevisioncontributes row-field withholding bindings, which are grouped into deterministic per-row output slots.- Return type:
- Parameters:
revision (ModeloRevision)
observations (Iterable[WithholdingObservation])
- class WithholdingClaveBreakdown(**data)[source]¶
Bases:
BaseModelOne per-clave row of the Modelo 190 retención reconciliation breakdown.
Groups the per-perceptor-clave withholding detail (the AEAT Diseño de Registros type-2 records) by
clave de percepciónand carries that clave’s distinct percepción count and percibido / retención magnitudes. The figures reuse the scalar withholding-fact arithmetic (resolve_withholding_binding_values()):percepcion_countis the distinct(perceptor, clave, subclave)count,percibido_totalispercibido_dinerario + percibido_especie, andretencion_totalisretencion_practicada + ingreso_a_cuenta. It is a projection of the same store the percepciones-count resolver reads, so the operator can reconcile the annual Modelo 190 totals against the individual Modelo 111 quarterly filings clave by clave.- Parameters:
clave (RetencionClave)
percepcion_count (int)
percibido_total (Decimal)
retencion_total (Decimal)
- clave: RetencionClave¶
- percepcion_count: int¶
- percibido_total: Decimal¶
- retencion_total: Decimal¶
- aggregate_withholding_by_clave(observations)[source]¶
Project withholding observations into
WithholdingClaveBreakdownrows.Pure function: identical observations in any order yield the same tuple, sorted by
clave. No new aggregation is introduced — the magnitudes apply the exactpercepcion_count/percibido_sum/retencion_sumfield arithmetic ofresolve_withholding_binding_values(), so the breakdown cannot drift from the bound facts that feed the calculation. Per clave, the distinct percepción key is(perceptor_tax_id, subclave)(the clave is the grouping axis).- Return type:
- Parameters:
observations (Iterable[WithholdingObservation])
- class WithholdingTotalsParity(**data)[source]¶
Bases:
BaseModelTotals-parity verdict between per-perceptor withholding rows and the Modelo 190 resumen-anual summary casillas.
Modelo 190’s summary casillas (
decl.percepciones-total,decl.retenciones-total) are computed by SUMMING the taxpayer’s four Modelo 111 quarterly filings (source = "relation_prefill",op = "sum"over casillas02/05/08/.../26and28respectively) — an entirely INDEPENDENT source from the per-perceptor-claveWithholdingObservationdetail (the AEAT Diseño de Registros type-2 “registro de perceptor” rows,source = "withholding") that materialises themodelo-190-perceptor-row-*bindings and the distinct-percepción count. Nothing in the registry cross-checks that the two sources agree.This model is the pure comparison result of that cross-check: the sum of every persisted perceptor’s
percibido_dinerario + percibido_especieagainst the resolveddecl.percepciones-totalvalue, and the sum of every persisted perceptor’sretencion_practicada + ingreso_a_cuentaagainst the resolveddecl.retenciones-totalvalue.is_consistentisTrueonly when both deltas are withintolerance— a divergence on either side surfaces as a loud, actionable finding (no-silent-under-declaration), never a silent pass.- Parameters:
- percepciones_row_total: Decimal¶
- percepciones_summary_total: Decimal¶
- percepciones_delta: Decimal¶
- retenciones_row_total: Decimal¶
- retenciones_summary_total: Decimal¶
- retenciones_delta: Decimal¶
- row_count: int¶
- tolerance: Decimal¶
- is_consistent: bool¶
- compute_withholding_totals_parity(observations, *, percepciones_summary_total, retenciones_summary_total, tolerance=Decimal('0.01'))[source]¶
Cross-check summed per-perceptor withholding rows against the resolved Modelo 190 summary casillas.
- Parameters:
observations (
Iterable[WithholdingObservation]) – The persisted per-perceptor-claveWithholdingObservationrows (the AEAT Diseño de Registros type-2 “registro de perceptor” detail).percepciones_summary_total (
Decimal) – The resolved value of casilladecl.percepciones-total(the M111-relation-derived summary total), typically read fromrevision.casilla_values["decl.percepciones-total"].retenciones_summary_total (
Decimal) – The resolved value of casilladecl.retenciones-total, typically read fromrevision.casilla_values["decl.retenciones-total"].tolerance (
Decimal) – Maximum absolute delta (EUR) that does not surface a divergence. Defaults to one cent, matching the registry’s standard rounding tolerance.
- Return type:
- Returns:
A
WithholdingTotalsParityverdict.is_consistentisFalsewhenever either summed total diverges from its corresponding summary casilla by more thantolerance— a missing or dropped perceptor row under-declares the row-level total below the summary casilla and must surface as a divergence, never silently collapse intois_consistent=True.