aeat.domain.calculations.registry._observation_fold module

One observation-fold helper for cross-filing fold-ins.

The single gather-and-fold primitive shared by both relation fold paths (the application-layer relation prefill and the domain-layer domain.calculations.registry.resolve_relation_values_from_observations()). It matches the source filings a RegistryFoldRequirement declares and extracts the source casilla value per period, then folds the gathered values through the requirement’s declared copy / sum aggregation to one Decimal.

Lives in the domain registry package (not the application source mesh) because the domain relation resolver consumes it and the hexagonal direction forbids a domain module importing the application layer.

See also

domain.calculations.registry._relations

Domain relation resolver that gathers and folds requirements here.

domain.calculations.registry._bindings_previous_filing

Previous-filing binding resolver that reuses fold_sum_or_copy().

gather_observed_requirement_values(requirement, observations)[source]

Return the source-casilla values matched for one fold requirement, per period.

Matches exactly one RegistryModeloObservation per declared source period and extracts the requirement’s single source CasillaId value from each. The returned tuple carries one value per requirement.periods entry, in declaration order, ready for fold_observed_requirement_values().

Return type:

tuple[Decimal, ...]

Parameters:
fold_sum_or_copy(op, values, *, subject, copy_unit)[source]

Fold a value sequence through the shared sum / copy arithmetic.

The one place sum (add every value) and copy (require exactly one value and return it) are implemented. subject and copy_unit carry the caller’s diagnostic vocabulary so a refused copy names the right entity (a relation requirement’s observation, or a binding’s source casilla). An op that is neither sum nor copy is rejected; callers handle any other op (e.g. the Modelo 130 prior_pagos_fraccionados identity) before delegating.

Used by both fold_observed_requirement_values() and domain.calculations.registry.resolve_previous_filing_binding_values().

Return type:

Decimal

Parameters:
fold_observed_requirement_values(requirement, values)[source]

Fold per-period source values through a requirement’s copy / sum op.

copy requires exactly one gathered value and returns it; sum adds the gathered values. This is the one fold both relation paths apply to a RegistryFoldRequirement; the period match is gather_observed_requirement_values().

Return type:

Decimal

Parameters:
resolve_observed_requirement_value(requirement, observations)[source]

Gather and fold one requirement to a single Decimal.

Convenience wrapper for callers that already hold the normalized RegistryModeloObservation rows.

Return type:

Decimal

Parameters: