aeat.domain.calculations.registry._validate_relation_sources module

Cross-model relation and previous-filing source validation helpers.

Validates cross-model relations declared on each ModeloRevision against the source ModeloDefinition, checking selector coverage, source-casilla-id existence, and period alignment.

See also

aeat.domain.calculations.registry._validate_source_casilla_ids

Shared source-casilla membership and non-canonical token diagnostics.

aeat.domain.calculations.registry._validate_relation_periods

Source revision selection and period/year coverage gates.

aeat.domain.calculations.registry._validate_previous_filing_sources

Sibling closure check for previous-filing binding selectors.

MODELO_303_IVA_COMPENSATION_BINDING_ID: Final[str]

The single M303 compensación-pendiente binding id, owned by the iva-wallet compensación decision (aggregation-taxonomy ADR ruling D3). This is the one canonical declaration of the identifier: the registry relation-source validator (below), the calculate orchestrator’s mesh exclusion, and the previous-filing exclusion all consume it rather than re-spelling the literal. It rides down here in the registry domain so both the domain validator and the application orchestrator (application -> domain) read one source of truth.

IVA_WALLET_OWNED_RELATION_TARGET_BINDINGS: frozenset[str]

The iva-wallet-owned relation-target slot binding set (aggregation-taxonomy ADR ruling D3): the M303 compensación-pendiente binding is owned by the iva-wallet compensación decision (resolved pre-mesh through _iva_wallet_gate), NOT by the relation mesh. It legitimately remains source = "previous_filing" while also being a relation’s target_binding — the iva-wallet gate strips it from the previous-filing resolution before the mesh runs. It is therefore the documented carve-out for the relation-vs-previous_filing collision gate below, and the same set the orchestrator excludes from previous-filing resolution.

validate_relation_closure(modelos, modelos_by_id)[source]

Validate cross-model relation closure for registry modelos.

Parameters:
Return type:

list[str]

validate_slot_source_hygiene(modelos, modelos_by_id)[source]

Validate the relation/previous_filing slot-source hygiene gates (taxonomy ADR ruling 3).

Two gates, applied per revision (defence-in-depth against the dual-modelling overlap the aggregation-taxonomy ADR closes at the root):

  1. A binding with source = "previous_filing" MUST satisfy the direct-selector predicate (_is_direct_previous_filing_binding). A NON-direct previous_filing binding (e.g. {source_modelo, source_casilla_id} with no period anchor) is a mis-stamped relation-materialisation slot and becomes a registry validation ERROR — it MUST declare source = "relation_prefill" instead.

  2. No binding may be BOTH a relation’s target_binding AND a previous_filing source. The two mechanisms (relation fold-in vs direct cross-period carry) must have disjoint declared ownership. The single documented carve-out is the iva-wallet-owned M303 compensación slot (D3): it is owned pre-mesh by the iva-wallet compensación decision, not by the relation mesh, and is exempt from this gate.

Parameters:
Return type:

list[str]