aeat.application.modelo._binding_resolution module

Application-owned binding input resolution for modelo calculations.

This module prepares binding, enum, and informational inputs for one RegistrySnapshot before the registry engine evaluates its ModeloRevision. Profile, backend mesh, borrador, and caller values are normalised as CalculationSourceResolution tiers, then the calculation assembly layer overlays them by precedence: profile, backend mesh, borrador, and finally caller overrides.

The module also owns the application-specific partial projection from available binding values to CasillaId inputs. That differs from the domain registry’s strict bound-input projection: live calculate paths may carry absent optional bindings while still projecting every value that did resolve.

See also

_calculation_resolution:

Merges these tiers and builds the canonical engine input maps.

resolve_bound_inputs_by_casilla_id():

Strict registry projection that requires every bound fact to be present.

_profile_binding:

Resolves profile-sourced bindings into decimal, enum, and date channels.

_borrador_binding:

Resolves Modelo 100 borrador snapshots as a precedence tier.

resolve_borrador_source_tier(*, bucket_id, snapshot, filing_year, period, borrador_snapshot_id, caller_binding_values, caller_enum_binding_values, borrador_snapshot_repository)[source]

Resolve the borrador precedence tier as a source-mesh resolution.

The RegistrySnapshot supplies the revision and modelo identity used to resolve the borrador source through the source mesh; the returned CalculationSourceResolution carries the typed borrador_provenance (snapshot id + sourced-binding trace) the persistence boundary consumes.

Caller-supplied BindingId values remain higher precedence than the snapshot, so the resolver receives both decimal and enum caller channels and omits any borrador value already owned by the caller.

See also

CalculationSourceResolution:

The shared carrier used by the precedence overlay.

Borrador100SnapshotRepository:

Loads the optional captured snapshot when a borrador id is supplied.

Return type:

CalculationSourceResolution

Parameters:
resolve_profile_source_tier(*, bucket_id, snapshot, caller_binding_values, caller_enum_binding_values, borrador_resolution, backend_binding_values)[source]

Resolve the profile precedence tier as a source-mesh resolution.

The RegistrySnapshot identifies the revision whose source = "profile" bindings are enrolled through the source mesh. Profile is the LOWEST precedence tier, so every binding the caller, borrador, or mesh backend already supplied is excluded here (the profile resolver never overrides a higher tier).

The borrador_resolution and backend values are passed only as ownership exclusions. They do not change profile facts; they prevent the profile tier from claiming a BindingId that a higher-precedence source already supplied.

See also

ProfileSourceResolver:

Source resolver that reads the stored user profile facts.

resolve_calculation_binding_channels():

Places this profile tier below backend, borrador, and caller tiers.

Return type:

CalculationSourceResolution

Returns:

A CalculationSourceResolution carrying the profile-owned bindings not already claimed by higher-precedence tiers.

Parameters:
reject_binding_channel_mismatch(revision, binding_values, enum_binding_values)[source]

Reject binding values supplied on the wrong engine channel.

The ModeloRevision determines channel ownership from formula consumption: enum dispatch bindings must arrive through enum_binding_values; decimal operands must arrive through binding_values. A mismatch raises ModeloError before the engine sees an apparently missing binding.

See also

enum_consumed_binding_ids():

Identifies bindings consumed by enum-dispatch formulas.

Return type:

None

Parameters:
lift_previous_filing_casilla_overrides_to_bindings(revision, casilla_inputs, resolved_bindings)[source]

Promote eligible previous-filing casilla overrides into binding values.

The ModeloRevision supplies the bound casilla and binding metadata. A caller may supply a CasillaId override for a bound casilla whose binding source is previous_filing when no resolver-produced binding value exists. This helper mirrors that override onto the matching BindingId so the registry engine’s bound-input consistency guards see the same source of truth in both channels. Existing resolved bindings are never overwritten.

See also

resolve_calculation_binding_channels():

Calls this after the precedence overlay settles.

Return type:

dict[TypeAliasType, Decimal]

Parameters:
resolve_declaration_period_inputs(revision, *, filing_year, period)[source]

Resolve work-unit period metadata into informational casilla inputs.

The ModeloRevision supplies the informational casillas eligible for metadata projection. Only casillas with unique filing_year or filing_period semantic roles are populated. The Period registry token is mapped to the ordinal expected by the registry snapshot; unsupported tokens or non-informational role targets raise ModeloError.

See also

casilla_id_for_unique_revision_semantic_role():

Enforces that each populated semantic role resolves to one casilla.

Return type:

dict[TypeAliasType, Decimal]

Parameters:
resolve_available_bound_inputs_by_casilla_id(revision, binding_values)[source]

Project available binding values into input values keyed by bound casilla.id.

The ModeloRevision supplies the bound casilla-to-binding mapping; only values already present in binding_values are projected. Missing optional bindings are skipped rather than treated as registry errors, which lets application calculate paths combine partial source mesh output with caller overrides before the engine runs.

Parameters:
Return type:

dict[TypeAliasType, Decimal]

Returns:

A dict keyed by CasillaId for every bound casilla whose binding value is currently available.

See also

resolve_bound_inputs_by_casilla_id():

Strict domain helper that rejects unknown or missing binding facts.

resolve_calculation_inputs():

Uses this partial projection when assembling engine inputs.