aeat.application.modelo._amendment_kind_resolution module

Period-aware amendment-kind resolution and the liability-increase guard.

AEAT’s amendment mechanism for a self-assessment changed over time (see _amendment_kind_regime for the full grounding). Before the autoliquidación rectificativa unification, a correction that raised the tax due filed as a complementaria (LGT art. 122.2) while a correction that lowered it required the separate solicitud de rectificación procedure (LGT art. 120.3) — a self-filed complementaria cannot lawfully lower a taxpayer’s own declared liability. This module is the single place that:

  • refuses an operator-requested CalculationRevisionAmendmentKind that the resolved (modelo, period) does not legally permit, naming the accepted kind set in the refusal (never a bare “invalid” message); and

  • classifies, for a pre-rectificativa period, whether the requested correction increases or decreases the taxpayer’s declared liability, so a complementaria requested for a liability-decreasing correction is refused with guidance toward the solicitud de rectificación procedure instead of being silently accepted as if it were lawful.

amend_modelo_revision() calls assert_amendment_kind_permitted() before it persists anything, so an illegal kind can never reach the catalogue.

See also

resolve_amendment_kind_regime():

Codified per-modelo, period-aware permitted-kind table this module binds to CalculationRevisionAmendmentKind.

amend_modelo_revision():

The composition path that calls this module’s guard before building the amendment revision.

assert_amendment_kind_permitted(*, modelo, period, amendment_kind)[source]

Refuse amendment_kind unless the resolved period legally permits it.

Reads the codified regime from resolve_amendment_kind_regime() for modelo and period and checks amendment_kind against the permitted set. A modelo with no codified rectificativa-adoption boundary (e.g. M130/M131, which carry no bundled rectificativa grounding) always resolves to the pre-rectificativa complementaria/sustitutiva pair, so requesting rectificativa for such a modelo is refused at every period until a bundled AEAT source grounds an effective date.

Raises:

AmendmentKindNotPermittedError – When amendment_kind is outside the resolved period’s permitted set. The refusal names both the requested kind and the full accepted set.

Return type:

None

Parameters:
liability_direction_for_amendment(*, baseline_result, corrected_result)[source]

Classify whether a correction increases, decreases, or leaves liability unchanged.

Thin, typed wrapper over classify_amendment_liability_direction() for callers inside the modelo application layer. baseline_result and corrected_result are the modelo’s signed final-result casilla value before and after the operator’s overrides.

The classification is load-bearing only for pre-rectificativa periods: INCREASE is complementaria territory (LGT art. 122.2); DECREASE is solicitud de rectificación territory (LGT art. 120.3) that a self-filed complementaria cannot lawfully carry — see amend_modelo_revision()’s pre-rectificativa complementaria-direction guard.

Return type:

AmendmentLiabilityDirection

Parameters:
assert_complementaria_liability_direction_permitted(*, modelo, period, amendment_kind, baseline_casilla_values, corrected_casilla_values)[source]

Refuse a pre-rectificativa complementaria that decreases liability.

Only load-bearing for a pre-rectificativa period (see resolve_amendment_kind_regime()): once rectificativa applies, both directions route through the unified mechanism and this guard is a no-op. For a pre-rectificativa period requesting COMPLEMENTARIA, sums the modelo’s codified final-result casilla(s) (result_disposition_casilla_ids()) before and after the operator’s overrides and refuses when the correction lowers the declared liability — that correction is legally a solicitud de rectificación (LGT art. 120.3), not a complementaria (LGT art. 122.2).

A modelo with no codified result-disposition spec, or a correction that does not touch the result casilla(s), is not refused: there is no basis to classify a direction, so the guard degrades to a no-op rather than fabricating a comparison.

Raises:

AmendmentComplementariaLiabilityDecreaseError – When a pre-rectificativa complementaria would lower the taxpayer’s declared liability.

Return type:

None

Parameters: