aeat.domain.calculations.registry._relations module¶
Relation helpers for cross-model registry dependencies.
Resolves cross-modelo source requirements and materialises relation values
for a ModeloRevision filing.
Relations declare which source filings and output casillas must be available
before the target modelo can be calculated.
See also
aeat.domain.calculations.registry._bindings_previous_filingSame requirement record reused by direct previous-filing carries.
aeat.domain.calculations.registry._observation_foldObservation fold helpers used to gather source casilla values.
aeat.domain.calculations.registry._relation_aggregationCanonical relation aggregation resolver used by this module.
- class RegistryFoldRequirement(**data)[source]¶
Bases:
BaseModelOne source-filing requirement for a cross-filing fold-in.
The single unified requirement record for both fold-in mechanisms: a cross-modelo relation fold (
relation_ids/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 prior shapes: a relation requirement fans pluralperiodsagainst a singlesource_casilla_idsmember, while aprevious_filingrequirement carries a singleperiodsmember against pluralsource_casilla_ids.legal_refsandsource_refsretain the originating relation/binding grounding for operator diagnostics. Each producer emits a single-element tuple where its cardinality is one; no value shifts, only the record TYPE unifies.Consumed by
relation_source_requirements(),resolve_relation_values_from_observations(), andaeat.domain.calculations.registry.previous_filing_observation_requirements().- Parameters:
source_modelo (ModeloId)
filing_year (int)
source_casilla_ids (tuple[CasillaId, ...])
binding_ids (tuple[BindingId, ...])
relation_ids (tuple[RelationId, ...])
target_bindings (tuple[BindingId, ...])
dependency_role (str)
dependency_treatment (str)
aggregation_op (str)
legal_refs (tuple[LegalRefId, ...])
source_refs (tuple[SourceRefId, ...])
- source_modelo: ModeloId¶
- filing_year: int¶
- filing_periods: tuple[Period, ...]¶
- periods: tuple[str, ...]¶
- source_casilla_ids: tuple[CasillaId, ...]¶
- binding_ids: tuple[BindingId, ...]¶
- relation_ids: tuple[RelationId, ...]¶
- target_bindings: tuple[BindingId, ...]¶
- dependency_role: str¶
- dependency_treatment: str¶
- aggregation_op: str¶
- legal_refs: tuple[LegalRefId, ...]¶
- source_refs: tuple[SourceRefId, ...]¶
- relation_source_requirements(revision, *, filing_year, period)[source]¶
Return requirement records needed to resolve relations for a filing.
- Parameters:
revision (
ModeloRevision) – TheModeloRevisionwhose relation declarations to inspect.filing_year (
int) – Target filing year; combined with each relation’s source offset to derive the expected source-modelo filing year.period (
str) – Target period token; filters relations bytarget_periodsand 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 typed relation values from caller-supplied external outputs.
external_outputsis keyed by relation id. Aggregation defaults to copy;{"op": "sum"}sums tuple values for annual summaries.- Parameters:
revision (
ModeloRevision) – TheModeloRevisionwhose relation definitions are resolved against the supplied external outputs.external_outputs (
Mapping[TypeAliasType,Decimal|tuple[Decimal,...]]) – Caller-supplied per-relation values keyed byRelationId; adecimal.Decimalundercopyaggregation or a tuple of Decimals undersum.period (
str|None) – Optional period token; restricts active relations to those whosetarget_periodsset contains it.
- Return type:
- resolve_relation_values_from_observations(revision, observations, *, filing_year, period)[source]¶
Resolve relation values from normalized filed-declaration observations.
- Parameters:
revision (
ModeloRevision) – TheModeloRevisionwhose relation declarations to resolve.observations (
Iterable[RegistryModeloObservation]) – Filed-declarationRegistryModeloObservationrows that supply the source values each relation consumes.filing_year (
int) – Target filing year; combined with each relation’s source offset to match observation rows.period (
str) – Target period token whose relation requirements drive observation matching.
- Return type:
- Returns:
Resolved
RelationIdvalues suitable foraeat.domain.calculations.registry._formula_runtime.calculate_registry_snapshot().
- materialize_relation_binding_values(revision, relation_values, *, period=None)[source]¶
Copy resolved relation values into their declared target bindings.
Relation ids remain the canonical formula-runtime keys. This helper is an additive bridge for registry rows that also declare
target_bindingso bound casillas can consume a relation-backed value without duplicating relation resolution in the application layer.- Parameters:
revision (
ModeloRevision) – TheModeloRevisionwhose relation-to-binding mappings are used to populate the returned dict.relation_values (
Mapping[TypeAliasType,Decimal]) – Already-resolved relation id to Decimal mapping.period (
str|None) – Optional period token; restricts active relations to those whosetarget_periodsset contains it.
- Return type:
- Returns:
Target
BindingIdvalues for relation-backed bound casillas.