aeat.application.modelo._iva_wallet_gate module¶
Modelo IVA wallet gate for calculation and filing lifecycle checks.
Modelo 303 prior-compensation belongs to the IVA wallet authority, not to the
generic previous-filing source mesh. This module uses the calculation
RegistrySnapshot and
ModeloRevision to route the wallet
decision into the prior-compensation binding, then checks a persisted
IvaCompensationReconciliationDecision
against the exported or filed
CalculationRevision.
The gate is deliberately repository-backed: transient wallet decisions cannot
feed the Modelo 303 engine unless the same decision is already present in
IvaWalletDecisionRepository for the
work-unit taxpayer and period. Calculation, verification, internal filing, and
export all replay this authority instead of trusting a caller-provided binding
value for casilla 110. Blocked, missing, stale, target-mismatched, or
amount-mismatched decisions raise
ModeloIvaWalletReconciliationBlockedError
before a revision, filing record, or fichero-BOE artefact can be persisted.
The only lazy path is local-authority derivation for a bucket-scoped
WorkUnit: it can persist a non-blocking local
recurrence decision, and a first_period_zero decision is accepted only when
profile activity-start evidence and the
RegistrySnapshot prove every prior
Modelo 303 compensation dependency is pre-activity.
See also
reconcile_modelo_303_iva_compensation():Builds and persists the reconciliation decision consumed here.
IvaWalletDecisionSourceResolver:Projects a non-blocking decision into calculation binding values.
_require_cross_period_clean_state():Treats matching IVA-wallet authority as the Modelo 303 compensation gate.
export_modelo_revision():Replays this gate before writing a Modelo 303 export artefact.
- exception ModeloIvaWalletReconciliationBlockedError(message=None, *, context=None, suggestion=None, translated_message=None)[source]¶
Bases:
ModeloErrorRaised when Modelo 303 calculation is blocked by IVA wallet reconciliation.
- Parameters:
- Return type:
None
- code: ClassVar[ErrorCode]¶
- ModeloIvaWalletReconciliationBlocked¶
- resolve_iva_compensation_decision_for_calculation(work_unit, *, snapshot, supplied_decision, repository, work_unit_repository=None, calculation_repository=None, binding_values, backend_binding_values, casilla_inputs, backend_casilla_inputs)[source]¶
Resolve the Modelo 303 IVA wallet decision that may feed calculation bindings.
The
WorkUnitfixes the bucket, taxpayer profile lookup, target period, and registry revision; theRegistrySnapshotis passed to the lazy reconciliation path when no caller-supplied or persisted wallet decision exists. A supplied decision must match the persistedIvaCompensationReconciliationDecision. If the caller supplied a prior-compensation binding or casilla without a decision, the function tries only the local-authority zero path and otherwise returnsNoneso calculation surfaces the seed/reconcile guidance instead of silently trusting the value.- Return type:
- Parameters:
work_unit (WorkUnit)
snapshot (RegistrySnapshot)
supplied_decision (object | None)
repository (IvaWalletDecisionRepository | None)
work_unit_repository (WorkUnitCatalogueRepositoryProtocol | None)
calculation_repository (CalculationRevisionCatalogueRepositoryProtocol | None)
- apply_iva_compensation_decision_binding(modelo, filing_year, period, *, bucket_id, revision, taxpayer_nif=None, casilla_inputs=None, backend_casilla_inputs=None, caller_binding_values, backend_binding_values, decision)[source]¶
Apply a non-blocking IVA wallet decision to Modelo 303 binding values.
The
ModeloRevisiondefines the binding channel; the decision amount is written only after target period and taxpayer identity checks pass. Caller and backend inputs for the same binding or casilla must either match the selected decision amount or are refused as conflicts. The effective value is then produced throughIvaWalletDecisionSourceResolver, so the calculation source mesh records the IVA-wallet provenance instead of a genericprevious_filingsource.
- require_persisted_iva_compensation_decision_for_work_unit(work_unit, *, supplied_decision, snapshot=None, repository=None)[source]¶
Require a supplied Modelo 303 wallet decision to match the persisted decision.
The optional
RegistrySnapshotgrounds first-period-zero decisions; when omitted, the function resolves the snapshot from the suppliedWorkUnit. This check prevents a transient or staleIvaCompensationReconciliationDecisionfrom feeding calculation values unless the repository contains the same authority record.- Return type:
- Parameters:
work_unit (WorkUnit)
supplied_decision (object)
snapshot (RegistrySnapshot | None)
repository (IvaWalletDecisionRepository | None)
- load_persisted_iva_compensation_decision_for_work_unit(work_unit, *, repository=None)[source]¶
Load the persisted IVA compensation decision for a
WorkUnit.- Return type:
- Returns:
The persisted
IvaCompensationReconciliationDecisionfor Modelo 303 work units, orNonewhen the work unit or bucket has no wallet authority record.- Parameters:
work_unit (WorkUnit)
repository (IvaWalletDecisionRepository | None)
- caller_supplied_prior_compensation_value(*, binding_values, backend_binding_values, casilla_inputs, backend_casilla_inputs)[source]¶
Return whether a Modelo 303 prior-compensation value was explicitly supplied.
The lazy local reconciliation must not fire when the operator or a backend resolver explicitly asserts the prior-compensation binding/casilla. That value needs reconciliation against a real wallet/seed decision, and the seed-verb guidance must surface.
- lazily_reconcile_local_iva_compensation_for_work_unit(work_unit, *, snapshot, repository=None, work_unit_repository=None, calculation_repository=None, persist=True)[source]¶
Auto-derive and persist the local-authority Modelo 303 compensation decision.
Calculate’s prior-compensation gate requires a persisted
IvaCompensationReconciliationDecision. In the seed-only local authority case, the local Modelo 303 recurrence is the authority, so derive and persist the decision here instead of refusing calculation.The
RegistrySnapshotsupplies the Modelo 303 revision context for the reconciliation service. Missing local recurrence is treated asfirst_period_zeroonly when the work unit’s profile activity-start date scopes every Modelo 303 compensation dependency out as pre-activity; otherwise the reconciliation remains a blocking missing-authority state.- Return type:
- Parameters:
work_unit (WorkUnit)
snapshot (RegistrySnapshot)
repository (IvaWalletDecisionRepository | None)
work_unit_repository (WorkUnitCatalogueRepositoryProtocol | None)
calculation_repository (CalculationRevisionCatalogueRepositoryProtocol | None)
persist (bool)
- require_persisted_iva_compensation_decision_matches_revision(work_unit, revision, *, repository=None)[source]¶
Return the IVA compensation decision when it matches the revision.
The check reads the supplied
CalculationRevisionand blocks verification, internal filing, or export when its Modelo 303 prior-compensation amount differs from the persisted wallet decision, when the decision targets another period, or when the decision is blocked/missing. Non-Modelo 303 work units returnNonebecause the IVA wallet authority owns only Modelo 303 prior compensation.- Return type:
- Returns:
The matching
IvaCompensationReconciliationDecisionfor Modelo 303, orNonefor non-Modelo 303 work units.- Parameters:
work_unit (WorkUnit)
revision (CalculationRevision)
repository (IvaWalletDecisionRepository | None)
- revision_iva_compensation_amount(revision)[source]¶
Return the Modelo 303 prior-compensation amount carried by a revision.
Reads the
CalculationRevisioncasilla values first, then binding overrides, matching the persisted calculation payload.- Return type:
- Parameters:
revision (CalculationRevision)
- iva_wallet_blocked_message(decision)[source]¶
Render a localized IVA wallet blocked message from a decision-like object.
- Return type:
- Parameters:
decision (_IvaWalletBlockedDecision)