aeat.application.modelo._prior_payment_advisory module

Calculate-path advisories around the Modelo 130 prior-payment carry.

Modelo 130 is cumulative from the start of the ejercicio: casilla 01 (Ingresos) accumulates year-to-date, so casilla 04 (importe del pago fraccionado) is the cumulative 20 % of the YTD rendimiento. Casilla 05 (“Pagos fraccionados anteriores”) is now a bound previous-filing carry, modelo-130-pagos-fraccionados-anteriores: for each same-ejercicio prior trimestre it adds the positive part of casilla 07 and subtracts casilla 16. The result is then consumed unchanged by casilla 07 = 04 - 05 - 06.

This module does not compute the carry. It emits non-blocking CalculationSourceDiagnostic advisories for the two calculate-path degradation cases around the live carry:

  • prior_payment_not_deducted fires only when a non-first trimestre has positive cumulative ingresos, casilla 05 still resolved to zero, and a real prior-trimestre Modelo 130 filing exists in the local CalculationObservationRepository. Under the Stage-2 carry, normal readable prior filings populate casilla 05 and this prior over-payment advisory stays silent.

  • prior_payment_minoracion_not_captured fires when a carried prior filing includes casilla 07 but lacks any casilla 16 entry. The registry resolver treats that absent minoración as Decimal("0") so the carry can continue, while the advisory names the evidence gap. A filed zero is captured evidence and stays silent.

The first-filer safeguard still keys off real stored observations, never a bare period token: a 1T target or a genuine first-obligation quarter has no prior trimestre to carry, so casilla 05 materialises zero absent-by-design.

See also

collect_bucket_aggregation_advisory_diagnostics():

Wires these advisories into the bucket-aggregation calculate path.

CalculationObservationRepository:

Supplies the persisted prior-filing observations inspected by both advisories.

CasillaId:

The validated registry casilla key type used for the carry and advisory targets.

collect_prior_payment_not_deducted_diagnostics(casilla_values, *, modelo, period_token, filing_year, observation_repository)[source]

Return an advisory when a non-first M130 trimestre under-deducts prior payments.

The advisory (reason = "prior_payment_not_deducted") fires exactly when the target period is a non-first trimestre, casilla 01 is strictly positive, casilla 05 still resolved to zero, AND a prior-trimestre Modelo 130 filing for the same ejercicio exists in observation_repository. In the current registry, the bound casilla-05 carry normally populates this deduction from readable observations; this advisory is the calculate-path degradation signal for a carry that could not populate despite a real prior filing. The last gate keeps a true first-obligation filer (whose casilla 05 is legitimately zero) silent.

Parameters:
  • casilla_values (Mapping[TypeAliasType, Decimal]) – The computed casilla values (engine result), keyed by CasillaId.

  • modelo (str) – The modelo identifier of the filing being calculated. Used to confirm the modelo is 130 (the cumulative pago-fraccionado form this carry applies to) before any catalogue scan.

  • period_token (str) – The bare registry period code of the target filing (e.g. "2T").

  • filing_year (int) – The ejercicio whose prior trimestres are scanned.

  • observation_repository (CalculationObservationRepository) – The local CalculationObservationRepository scanned for a prior-period filing — the first-filer safeguard.

Return type:

tuple[CalculationSourceDiagnostic, ...]

Returns:

A tuple of CalculationSourceDiagnostic advisories — empty when no under-deduction is detected, otherwise the single advisory.

See also

collect_prior_payment_minoracion_not_captured_diagnostics():

Covers the companion evidence-gap case where the carry resolves but a prior casilla-16 minoración was absent from the stored observation.

CalculationObservationRepository:

Provides the first-filer safeguard and prior-filing evidence.

collect_prior_payment_minoracion_not_captured_diagnostics(*, modelo, period_token, filing_year, observation_repository)[source]

Return an advisory when a carried prior M130 filing lacks its casilla-16 minoración.

The casilla-05 carry (modelo-130-pagos-fraccionados-anteriores) computes Σ max(0, prior 07_q) Σ prior 16_q. A prior-trimestre filing that carries casilla 07 (a real pago fraccionado the carry deducts) but LACKS any casilla-16 entry is “not captured” - distinct from a filing that genuinely declared casilla 16 = 0. Per the ratified ADR 2026-06-13-modelo-130-pagos-fraccionados-carry casilla-16 filed-zero-vs-not-captured distinction, the carry proceeds (treating the absent minoración as zero) but the gap MUST surface as a non-blocking advisory naming it - the minoración is never silently dropped (no-silent-under-declaration).

The advisory fires for the SAME ejercicio’s prior trimestres of a non-first target quarter, only when at least one prior filing carries casilla 07 but no casilla-16 entry. A prior filing that declares casilla 16 = 0 explicitly is a silent no-op (the value is captured; it just happens to be zero).

Parameters:
  • modelo (str) – The modelo identifier of the filing being calculated; the advisory applies only to Modelo 130.

  • period_token (str) – The bare registry period code of the target filing.

  • filing_year (int) – The ejercicio whose prior trimestres are scanned.

  • observation_repository (CalculationObservationRepository) – The local CalculationObservationRepository scanned for prior-period observations.

Return type:

tuple[CalculationSourceDiagnostic, ...]

Returns:

A tuple of CalculationSourceDiagnostic advisories — empty when every carried prior filing captured its casilla-16 minoración, otherwise the single prior_payment_minoracion_not_captured advisory.

See also

collect_prior_payment_not_deducted_diagnostics():

Covers the degraded carry case where casilla 05 stayed zero despite a real prior M130 filing.

CalculationObservationRepository:

Supplies the prior-filing observations whose casilla-16 presence distinguishes filed zero from not captured.