aeat.application.calculations._binding_prefill module¶
Binding prefill: resolve previous_filing bindings from prior filings.
Used by PreviousFilingSourceResolver for the source-mesh
calculation path and by
extract_modelo_303_local_iva_compensation_recurrence()
for the IVA wallet comparison path.
One of three distinct prefill tiers, NOT to be merged: this is the
PREVIOUS-FILING direct-carry tier. The other two are the relation tier
(_relation_prefill) and the AEAT borrador
pre-fill tier (the registry aeat_prefilled flag, an AEAT-live source). They
share only the word “prefill”; each routes a different source through a
different mechanism.
Sister module to _relation_prefill. The runtime distinguishes
relation leaves (cross-revision aggregations declared as
RelationDefinition records) from
previous_filing bindings (declared as
DataBindingDefinition with
source = "previous_filing").
Modelo 390 uses bindings — modelo 200 uses relations — both express
“sum a prior modelo’s casilla across periods” but route through
different schema entities.
Prior-filing values are gathered as CasillaObservation records and
merged inside
RegistryModeloObservation rows before
the binding is resolved.
The strict registry boundary remains
previous_filing_observation_requirements()
and
resolve_previous_filing_binding_values();
this module is the application reader that supplies local observations from
CalculationObservationRepository and returns
BindingPrefillReport coverage.
- class PrefilledBinding(**data)[source]¶
Bases:
BaseModelOne resolved previous-filing binding with local-source provenance.
Emitted by
resolve_bindings_from_local_store()and collected inBindingPrefillReport. Thesource_*fields point back to theRegistryModeloObservationrows that satisfied the registry previous-filing requirement.- Parameters:
- binding_id: BindingId¶
- value: Decimal¶
- provenance: str¶
- source_kind: str¶
- source_modelo: str¶
- source_filing_year: int¶
- source_periods: tuple[str, ...]¶
- resolved_at: datetime¶
- class BindingPrefillReport(**data)[source]¶
Bases:
BaseModelOutcome of one direct previous-filing binding-prefill pass.
binding_valuesis the mapping passed tocalculate_registry_snapshot();prefilledkeeps thePrefilledBindingprovenance used byPreviousFilingSourceResolverwhen stamping source-mesh results.- Parameters:
prefilled (tuple[PrefilledBinding, ...])
- prefilled: tuple[PrefilledBinding, ...]¶
- binding_values: Mapping[BindingId, Decimal]¶
- class LocalIvaCompensationRecurrence(**data)[source]¶
Bases:
BaseModelLocal Modelo 303 recurrence evidence extracted for wallet reconciliation only.
This is comparison evidence. It does not choose the effective casilla 110 value; the
IvaWalletDecisionSourceResolverand wallet reconciliation decision remain the only selectors.- Parameters:
- binding_id: BindingId¶
- amount: Decimal¶
- source_kind: str¶
- source_modelo: str¶
- source_filing_year: int¶
- source_periods: tuple[Period, ...]¶
- resolved_at: datetime¶
- source_locator: str | None¶
- resolve_bindings_from_local_store(snapshot, *, repository=None, iva_history_repository=None, captured_at=None, activity_start_date=None, excluded_binding_ids=None)[source]¶
Resolve every
previous_filingbinding the revision declares against observations in the local store.The caller provides a
RegistrySnapshot; this function asks the registry forRegistryFoldRequirementrecords, loads matchingRegistryModeloObservationrows, then delegates the final value calculation toresolve_previous_filing_binding_values().- Parameters:
snapshot (
RegistrySnapshot) – TheRegistrySnapshotwhose revision’sprevious_filingbindings are resolved from the local calculation observation store.repository (
CalculationObservationRepository|None) – OptionalCalculationObservationRepository; defaults to the active-bucket repository whenNone.iva_history_repository (
IvaCompensationHistoryRepository|None) – OptionalIvaCompensationHistoryRepositoryconsulted for the IVA compensation prior-balance bindings; defaults to the active-bucket repository whenNone.captured_at (
datetime|None) – Optional capture timestamp recorded on the produced prefill records; defaults to the canonical clock whenNone.activity_start_date (
date|None) – Optional operator-declared activity start. Source periods strictly before this date are no-prior-obligation periods and resolve to a neutral zero instead of requiring observed filings.excluded_binding_ids (
frozenset[TypeAliasType] |None) – Optional previous-filing binding ids to leave unresolved because another authority owns them.
- Return type:
Returns a
BindingPrefillReportcarrying the resolvedbinding_valuesmapping (suitable for passing throughcalculate_registry_snapshot’sbinding_values=argument) plus a tuple ofPrefilledBindingrecords with provenance per entry.Bindings the local store cannot satisfy are skipped silently — the engine emits blank cells the operator fills by hand. Strict enforcement (refusing the export when prior filings are missing) is the caller’s choice via the prefill report’s coverage.
See also
PreviousFilingSourceResolveradapts this report toCalculationSourceResolution;resolve_relations_from_local_store()resolves the separaterelation_prefillsource family over the same observation repository.
- extract_modelo_303_local_iva_compensation_recurrence(snapshot, *, repository=None, iva_history_repository=None, captured_at=None)[source]¶
Extract the local Modelo 303 compensation recurrence for comparison.
This is the explicit wallet-feeding path over
IvaCompensationHistoryRepository: it reconstructs the local previous-filing amount soreconcile_modelo_303_iva_compensation()can compare it with current AEAT wallet evidence.- Parameters:
snapshot (
RegistrySnapshot) – TheRegistrySnapshotidentifying the Modelo 303 target revision.repository (
CalculationObservationRepository|None) – OptionalCalculationObservationRepository; defaults to the active-bucket repository whenNone.iva_history_repository (
IvaCompensationHistoryRepository|None) – OptionalIvaCompensationHistoryRepositoryconsulted for prior compensation balances; defaults to the active-bucket repository whenNone.captured_at (
datetime|None) – Optional capture timestamp recorded on the produced prefill records; defaults to the canonical clock whenNone.
- Return type:
tuple[LocalIvaCompensationRecurrence|None,BindingPrefillReport]
The returned amount is the locally reconstructed prior compensation balance for the target Modelo 303 period. Callers must feed it into reconciliation; they must not use it directly as the effective value while fresh AEAT wallet evidence exists.
Returns a 2-tuple of a
LocalIvaCompensationRecurrence(orNonewhen no compensation binding is present) and the underlyingBindingPrefillReport.