cadrumo.domain.calculations.registry.bindings_previous_filing module¶
Previous-filing binding selectors, requirements, and resolvers.
The ModeloRevision supplies
previous_filing
BindingDefinition
declarations; this module turns those selectors into
RegistryFoldRequirement source
requirements and resolved
BindingId values.
See also
cadrumo.domain.calculations.registry.bindingsPublic import surface that re-exports these previous-filing helpers.
cadrumo.domain.calculations.registry.relationsRelation-fold sibling that materialises cross-modelo source values.
cadrumo.domain.calculations.registry.observation_foldShared fold helpers for observed casilla values.
- class PreviousFilingSourceReference(source_modelo, required_periods, source_casilla_ids, filing_year_delta=0, max_year_delta=None, has_variable_year_offset=False)[source]¶
Bases:
objectCanonical source reference extracted from a typed previous-filing selector.
The reference names the source
ModeloId, required periods, and sourceCasillaIdvalues declared by one previous-filing binding selector.filing_year_deltaandmax_year_deltaride along so a build-time year-coverage check can derive the exact source-year interval a selector requires without re-parsing the selector a second time.has_variable_year_offsetisTruefor a provider whose temporal member is the expanding span or a period offset: both produce PER-ANCHOR year deltas (PreviousFilingProvider.required_period_anchors_for_target()returns several(period_year_delta, period)pairs, each with its own offset) rather than the single uniform offset a coverage check keyed on one interval can represent.- Parameters:
-
source_modelo:
TypeAliasType¶
- previous_filing_source_reference(binding)[source]¶
Return the
PreviousFilingSourceReferencefor aprevious_filingbinding.The supplied
BindingDefinitionis parsed through the same selector model used byprevious_filing_observation_requirements().- Return type:
- Parameters:
binding (BindingDefinition)
- periodic_carry_bindings_for_period(revision, *, period=None)[source]¶
Return the revision’s periodic carry bindings with the periods they cover.
A periodic carry is a binding whose provider names a source modelo and a PERIOD-RELATIVE temporal member – the target-period offset or the prior- quarter expanding span. Both members state a source window that moves with the target period rather than naming a fixed one, which is what makes the declaration a carry between consecutive filings of a periodic modelo.
The provider kind is deliberately not part of the test: the same carry may be declared through a
previous_filingprovider or through arelation_prefillone, and a consumer asking which periods a modelo carries between filings must see both.The covered periods come from the binding’s own
target_periodsapplicability when it declares one. When it does not, they are derived from the revision’s filing schedules: a schedule period is covered when the temporal member yields a source anchor for it, so a member that cannot interpret a cadence (the expanding span against a monthly code) simply does not cover it rather than being assumed to.Core types:
ModeloRevision.- Return type:
- Parameters:
revision (ModeloRevision)
period (str | None)
- previous_filing_observation_requirements(revision, *, filing_year, period)[source]¶
Return source requirements needed by direct previous-filing bindings.
The
ModeloRevisionis scanned for directprevious_filingbindings, and each selector becomes aRegistryFoldRequirementnaming source modelo/year/period,BindingIdconsumers, and source casilla ids.- Return type:
- Parameters:
revision (ModeloRevision)
filing_year (int)
period (str)
- resolve_previous_filing_binding_values(revision, observations, *, filing_year, period, activity_start_date=None, excluded_binding_ids=None)[source]¶
Resolve direct previous-filing bindings from observed filed declarations.
The
ModeloRevisionsupplies the binding selectors and aggregation operators;observationssupply the filed casilla values they fold. The returned mapping is keyed byBindingIdand carries resolveddecimal.Decimalvalues for formula runtime consumption.
- class PreviousFilingProvider(**data)[source]¶
Bases:
BaseModelTyped provider model for a
previous_filingbinding declaration.The source coordinate is split in two:
source_modeloplus the source casilla ids name WHICH filed values are read, andtemporalnames WHEN they were filed, relative to the target filing context. The temporal axis is the shared closed union, so the six mutually exclusive period fields this model used to carry – and the hand-written validators that policed their legal combinations – are replaced by members that cannot express an illegal combination at all.- Parameters:
data (Any)
- kind: Literal[BindingSourceKind.PREVIOUS_FILING]¶
- source_modelo: ModeloId¶
- temporal: BindingTemporalSelector¶
- source_casilla_ids: tuple[CasillaId, ...]¶
- source_casilla_id: CasillaId | None¶
- required_source_casilla_ids: tuple[CasillaId, ...] | None¶
- grouping: Literal['per_grupo_member'] | None¶
- property required_periods: tuple[str, ...]¶
Return the source periods the temporal member names, if any.
same_target_context, the period offset, and the expanding span name no fixed period set: their periods depend on the target period and are produced byrequired_period_anchors_for_target()instead.
- property uniform_filing_year_delta: int¶
Return the single year offset every anchor shares, or zero.
Only
FilingYearOffsetstates one uniform offset. The period offset and the expanding span carry a per-anchor year delta instead, which is whyhas_variable_year_offsetexists.
- property has_variable_year_offset: bool¶
Whether the anchors carry per-anchor year deltas rather than one offset.
- property max_year_delta: int | None¶
Return the absolute bound on anchor year deltas the member declares.
- required_period_anchors_for_target(target_period)[source]¶
Return source year-offset and period anchors for a target period.
Each year offset is the TOTAL distance from the target filing year, so a caller derives the source year as
filing_year + year_deltaand never addsuniform_filing_year_deltaa second time.
- validate_previous_filing_binding(binding)[source]¶
Validate a previous_filing binding at registry-build time.
Accumulating
list[str]validator: validates the selector shape againstPreviousFilingProviderand lifts the previous-filing op/source invariants for aBindingDefinitionto build time, preserving the underlying pydantic field error.- Return type:
- Parameters:
binding (BindingDefinition)
- is_direct_previous_filing_binding(binding)[source]¶
Whether
bindingcarries a DIRECT previous-filing selector shape.Every real caller passes a
source == "previous_filing"binding (the only source this predicate is meaningful for), sobinding.provideris already hydrated intoPreviousFilingProviderby construction (theBindingProviderunion hydrates it at construction). Reading through the declared model –_previous_filing_selector, the same helperprevious_filing_observation_requirements()and_aggregate_previous_filing_binding()already call – rather than string-literaldict.get()keys means a field rename onPreviousFilingProviderfails loud instead of silently making every direct binding register as non-direct: this predicate backs the registry-build refusal (_validate_relation_sources.py) that aprevious_filingbinding must satisfy the direct-selector shape or declarerelation_prefillinstead, so a silently wrongFalsehere is a validation gate going quiet, not a benign miss.- Return type:
- Parameters:
binding (BindingDefinition)
- previous_filing_binding_source_casilla_ids(binding)[source]¶
Return the source casilla ids a
previous_filingbinding targets.The canonical, typed way to ask “which casilla(s) does this previous_filing binding read from” – delegates to the same
_previous_filing_source_ids()normalisation every other consumer of this selector uses, so a caller reading only the singularsource_casilla_idkey via a rawselector_as_dict(binding).get(...)silently misses any binding declaring the pluralsource_casilla_idsform instead, indistinguishable from “this binding targets no casilla at all”. Reading throughPreviousFilingProvideralso means a renamedsource_casilla_id/source_casilla_idsfield raises here, rather than silently returning an empty tuple for every binding.Returns an empty tuple for a binding that is not
previous_filingat all – a real, different fact from a malformed or drifted selector.- Return type:
- Parameters:
binding (BindingDefinition)