cadrumo.domain.calculations.registry.relations module¶
Cross-filing fold requirements and values for relation-prefill bindings.
A relation_prefill binding declares a fold from another modelo’s filed
values – or from an earlier period of this one – into a slot of the target
filing. This module turns those declarations into the source requirements that
must be satisfied before the target modelo can be calculated, and resolves the
folded values once the source observations are available.
The fold used to be declared by a separate relation family keyed by its own identifier. It is now the binding’s own provider, so the binding id is the key everywhere: one declaration, one identity, one inheritance rule.
See also
cadrumo.domain.calculations.registry.bindings_previous_filingSame requirement record reused by direct previous-filing carries.
cadrumo.domain.calculations.registry.observation_foldObservation fold helpers used to gather source casilla values.
- source_presence_gaps(*, required_source_casilla_ids, source_presence_groups, observed_source_casilla_ids)[source]¶
Return missing mandatory casillas and unsatisfied any-of groups.
This is the single enforcement primitive for registry-derived previous- filing source presence. Adapters and application gates consume the same result instead of reinterpreting candidate sets independently.
- class RegistryFoldRequirement(**data)[source]¶
Bases:
BaseModelOne source-filing requirement for a cross-filing fold-in.
The single unified requirement record for both fold mechanisms: a cross-modelo
relation_prefillfold (target_bindingspopulated) and a same-modelo directprevious_filingcarry (binding_idspopulated). Both the source-period and source-casilla axes are PLURAL so the record is a superset of the two shapes: a relation-prefill requirement fans pluralperiodsagainst a singlesource_casilla_idsmember, while aprevious_filingrequirement carries a singleperiodsmember against pluralsource_casilla_ids.legal_refsandsource_refsretain the originating binding’s grounding for operator diagnostics.Consumed by
relation_source_requirements(),resolve_relation_values_from_observations(), andcadrumo.domain.calculations.registry.bindings_previous_filing.previous_filing_observation_requirements().- Parameters:
data (Any)
- source_modelo: ModeloId¶
- filing_year: FilingYear¶
- filing_periods: tuple[Period, ...]¶
- periods: tuple[RegistrySelectorPeriodCode, ...]¶
- source_casilla_ids: tuple[CasillaId, ...]¶
- required_source_casilla_ids: tuple[CasillaId, ...] | None¶
- source_presence_groups: tuple[tuple[CasillaId, ...], ...]¶
- binding_ids: tuple[BindingId, ...]¶
- target_bindings: tuple[BindingId, ...]¶
- dependency_role: RelationDependencyRoleField | None¶
- dependency_treatment: RelationDependencyTreatmentField | None¶
- aggregation_op: RelationAggregationOp | None¶
- legal_refs: tuple[LegalRefId, ...]¶
- source_refs: tuple[SourceRefId, ...]¶
- relation_prefill_bindings_for_period(revision, *, period=None)[source]¶
Return this revision’s relation-prefill bindings applicable to a period.
The binding’s own
applicabilityis what scopes it now; the relation’starget_periodsmoved there in the same change that folded the relation into the provider, so period scoping has one home rather than two.Core types:
ModeloRevision.- Return type:
tuple[tuple[BindingDefinition,RelationPrefillProvider],...]- Parameters:
revision (ModeloRevision)
period (str | None)
- relation_requirement_index(requirements)[source]¶
Index canonical fold requirements by every target binding they satisfy.
relation_source_requirementsdeliberately coalesces source filings that satisfy more than one binding. Consumers nevertheless need a direct binding-id lookup to project the one requirement’s source identity, treatment, and grounding. Keeping that fan-out here means every consumer gets the same requirement object instead of reconstructing partial metadata with a local comprehension.- Return type:
dict[TypeAliasType,RegistryFoldRequirement]- Parameters:
requirements (Iterable[RegistryFoldRequirement])
- relation_source_requirements(revision, *, filing_year, period)[source]¶
Return requirement records needed to resolve relation prefills for a filing.
- Parameters:
revision (
ModeloRevision) – TheModeloRevisionwhose relation-prefill bindings to inspect.filing_year (
int) – Target filing year; combined with each provider’s temporal member to derive the expected source-modelo filing year.period (
str) – Target period token; filters bindings by applicability and seeds the source-period derivation.
- Return type:
- Returns:
RegistryFoldRequirementrows keyed by source modelo/year/period and source casilla.
- resolve_relation_values(revision, external_outputs, *, period=None)[source]¶
Resolve relation-prefill values from caller-supplied external outputs.
external_outputsis keyed by target binding id.copyfolds one Decimal through unchanged;sumadds the tuple of matched per-period values.- Parameters:
revision (
ModeloRevision) – TheModeloRevisionwhose relation-prefill bindings are resolved against the supplied outputs.external_outputs (
Mapping[TypeAliasType,Decimal|tuple[Decimal,...]]) – Caller-supplied per-binding values keyed byBindingId; adecimal.Decimalundercopyaggregation or a tuple of Decimals undersum.period (
str|None) – Optional period token; restricts active bindings to those whose applicability admits it.
- Return type:
- resolve_relation_values_from_observations(revision, observations, *, filing_year, period)[source]¶
Resolve relation-prefill values from normalized filed-declaration observations.
- Parameters:
revision (
ModeloRevision) – TheModeloRevisionwhose relation-prefill bindings to resolve.observations (
Iterable[RegistryModeloObservation]) – Filed-declarationRegistryModeloObservationrows that supply the source values each fold consumes.filing_year (
int) – Target filing year; combined with each provider’s temporal member to match observation rows.period (
str) – Target period token whose requirements drive observation matching.
- Return type:
- Returns:
Resolved
BindingIdvalues suitable forcadrumo.domain.calculations.registry.formula_runtime.calculate_registry_snapshot().
- relation_prefill_values_as_binding_values(revision, values, *, period=None)[source]¶
Project resolved relation-prefill values onto their binding ids.
Relation absorption makes the fold slot and its former target binding one declaration. This small projection remains useful at boundaries that receive a pre-resolved map and need to merge it with ordinary binding inputs; it deliberately accepts only the active provider binding ids and never translates a retired relation id.
Core types:
ModeloRevision.