cadrumo.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.

Projecting resolved binding values onto bound CasillaId inputs is registry-owned rather than an application concern: see resolve_available_bound_inputs_by_casilla_id(). Completeness and unrouted-input concerns remain advisory or verify-gate responsibilities rather than a second projection contract.

See also

calculation_resolution:

Merges these tiers and builds the canonical engine input maps.

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, operation)[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, operation, profile)[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, boolean_binding_values=None)[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. Channel ownership for the BOOLEAN channel comes from the binding’s own declared value contract rather than from consumption, and is enforced for the profile-sourced bindings whose resolver owns that channel. 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:
class DeclarationPeriodInputs(casilla_inputs=<factory>, text_casilla_inputs=<factory>)[source]

Bases: object

Work-unit metadata projected onto its two typed engine channels.

casilla_inputs carries the int-family filing_year role on the Decimal channel; text_casilla_inputs carries the string-family filing_period role, whose registry data_type = "period_code" binds it to the typed text-scalar channel and its period_code validator.

Parameters:
casilla_inputs: dict[TypeAliasType, Decimal]
text_casilla_inputs: dict[TypeAliasType, str]
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 filing_year role lands as a Decimal and the filing_period role as the canonical Period registry token ("1T", "EXT-1T"), which is the form AEAT accepts and the only representation total over every declared period. A non-informational role target raises ModeloError.

See also

casilla_id_for_unique_revision_semantic_role():

Enforces that each populated semantic role resolves to one casilla.

Return type:

DeclarationPeriodInputs

Parameters: