cadrumo.application.calculations.iva_wallet_reconciliation module¶
IVA compensation wallet reconciliation orchestration.
The live AEAT wallet is external state. Local Modelo 303 recurrence is internal reconstruction. This module is the application boundary that turns those evidence sources, plus an explicit taxpayer override when present, into the effective binding decision consumed by Modelo 303 calculation.
The pure decision logic
(reconcile_iva_compensation_wallet()
and its wallet/recurrence predicates) lives in
reconciliation; it consumes structural
ports such as
IvaCompensationWalletObservationProtocol
and
LocalIvaCompensationRecurrenceProtocol
so the domain never imports the Sede adapter. This module orchestrates
CalculationObservationRepositoryProtocol reads,
IvaWalletDecisionRepositoryProtocol persistence, and
source-mesh resolution around that pure decision.
Binding resolution reads its active revision through a
RegistrySnapshot supplied via the
source mesh context.
See also
extract_modelo_303_local_iva_compensation_recurrence()Reconstructs the local Modelo 303 recurrence compared with wallet evidence.
CalculationSourceResolutionThe source-mesh envelope produced by
IvaWalletDecisionSourceResolver.
- class IvaCompensationReconciliationReport(**data)[source]¶
Bases:
BaseModelApplication-level reconciliation result for one Modelo 303 target.
Carries the domain
IvaCompensationReconciliationDecisionplus theBindingPrefillReportused to reconstruct the local recurrence side of the comparison.- Parameters:
decision (IvaCompensationReconciliationDecision)
prefill_report (BindingPrefillReport)
- decision: IvaCompensationReconciliationDecision¶
- prefill_report: BindingPrefillReport¶
- class IvaWalletDecisionSourceResolver(decision)[source]¶
Bases:
objectSource-mesh adapter for persisted Modelo 303 IVA wallet decisions.
Owns
iva_wallet_decisionand materialises themodelo-303-compensacion-pendiente-anterioresbinding from a persistedIvaCompensationReconciliationDecision. The returnedCalculationSourceResolutioncarries the selected amount plus provenance for every authority source that participated in the wallet/filed-history/local-recurrence decision.- Parameters:
decision (IvaCompensationReconciliationDecision | None)
-
owned_sources:
ClassVar[tuple[BindingSourceKind,...]]¶
- binding_id¶
- resolve(context)[source]¶
Resolve the Modelo 303 IVA wallet decision binding for
context.- Return type:
- Returns:
An empty resolution when the modelo is not Modelo 303 or no decision was supplied, otherwise the resolved
CalculationSourceResolutioncarrying the selected amount and its provenance.- Raises:
IvaCompensationReconciliationInputError – When the decision does not target this filing year and period, blocks the calculation, or carries no selected amount.
- Parameters:
context (CalculationSourceContext)
- reconcile_modelo_303_iva_compensation(snapshot, *, taxpayer_nif, wallet, repository, decision_repository, override=None, decided_at=None, max_wallet_age_days=31, treat_absent_recurrence_as_first_period=False, local_evidence_found_but_unusable=False, local_recurrence, prefill_report, persist=True, operation)[source]¶
Resolve, compare, and optionally persist the Modelo 303 IVA wallet decision.
The function validates wallet evidence against the target
RegistrySnapshot, reconstructs local recurrence throughextract_modelo_303_local_iva_compensation_recurrence(), delegates authority selection toreconcile_iva_compensation_wallet(), and persists the resultingIvaCompensationReconciliationDecisionthroughIvaWalletDecisionRepositoryProtocolwhenpersistis true.- Parameters:
snapshot (
RegistrySnapshot) – TheRegistrySnapshotidentifying the Modelo 303 target revision.taxpayer_nif (
str) – Taxpayer identifier expected to match live wallet evidence.wallet (
IvaCompensationWalletObservationProtocol|None) – Live AEAT wallet observation to reconcile, when available.repository (
CalculationObservationRepositoryProtocol) – RequiredCalculationObservationRepositoryProtocolused to read prior local recurrence.decision_repository (
IvaWalletDecisionRepositoryProtocol) – RequiredIvaWalletDecisionRepositoryProtocolused to persist the resulting wallet authority. When persistence is enabled, it must use the same encrypted storage backend asrepository.override (
IvaCompensationOverride|None) – OptionalIvaCompensationOverrideevidence when the operator has resolved a divergence.decided_at (
datetime|None) – Decision timestamp override for deterministic replay and tests.max_wallet_age_days (
int) – Maximum accepted age for live wallet evidence.treat_absent_recurrence_as_first_period (
bool) – WhenTrueand there is no live wallet and no prior local recurrence, treat the target as the taxpayer’s FIRST IVA period:iva.compensacion-pendiente-periodos-anterioresis zero per LIVA art. 99.5 (no prior compensation balance can exist), yielding the non-blockingfirst_period_zerodecision instead of themissingblock. The caller asserts first-period status (e.g. the calculate path verifies no prior 303 compensation history exists). It NEVER fabricates a non-zero balance: a present recurrence still flows through normally.local_evidence_found_but_unusable (
bool) – Whether the caller FOUND a prior local record and could not interpret it as prior-compensation evidence. Only the caller knows this: an absent amount looks the same here whether nothing was stored or something was and could not be read. It changes no outcome, only what the no-authority decision says, so an operator is not told nothing exists while their own prior record sits in the store.local_recurrence (
LocalIvaCompensationRecurrence|None) – Required caller-resolved canonical recurrence, or explicitNonewhen the caller found no admissible recurrence.prefill_report (
BindingPrefillReport) – Required report from the same recurrence resolution. Reconciliation never performs a second repository fallback.persist (
bool) – Whether to store the resulting decision for later calculation replay.operation (
PinnedAuthorityOperation) – Caller-owned generation-pinned authority operation used to resolve first-period governed facts.
- Return type:
The local side is not recomputed here. It is read through the same previous-filing binding resolver used by the calculation chain.
Returns an
IvaCompensationReconciliationReport.See also
IvaWalletDecisionSourceResolverConverts a persisted non-blocking decision into the Modelo 303
iva_wallet_decisionsource value.