Source code for aeat.domain.renta._first_slice_routing_integrity
"""Snapshot-time referential integrity for the first-slice routing table.When the registry builds a Modelo 100 snapshot, every casilla id anactual ``ledger_renta_expense_aggregation`` binding on THAT revisiontargets MUST be a real casilla on the same revision. A divergencebetween a revision's own bindings and its own casilla set is asnapshot-build error, not a silent runtime ``KeyError`` when the rentadeductibility validator runs.This check is intentionally scoped to each revision's OWN bindings(:func:`~aeat.domain.calculations.registry.renta_first_slice_binding_target_casillas`),not the universal BOE-prescribed:data:`aeat.domain.renta._first_slice_routing.FIRST_SLICE_EXPENSE_CASILLAS`codomain spanning every filing year. Casilla ids are added, split, andrenumbered across Modelo 100 revisions -- for example "Aportaciones amutualidades alternativas" shares a combined casilla with SeguridadSocial contributions (id ``0186``) on the 2020-2022 revisions but getsits own dedicated casilla (id ``0195``) from 2023 onward. Revisionsthat declare no ``ledger_renta_expense_aggregation`` bindings at all(the ledger-aggregation mechanism did not exist for them yet) have alegitimately empty required set; requiring the full universal codomainon every revision would fail revisions that never route through it.This check is owned by the ``renta`` domain because the routing tableis renta domain knowledge. The registry must not import ``renta``directly -- that reverses the dependency direction the hexagonalarchitecture enforces. Instead this module registers a:class:`~aeat.domain.calculations.registry.CrossDomainSnapshotCheck`with the registry validator via:func:`~aeat.domain.calculations.registry.register_cross_domain_snapshot_check`.The registration runs at ``renta`` package import time (see:mod:`aeat.domain.renta` ``__init__``); the registry calls the checkthrough the abstract Protocol without naming ``renta``."""from__future__importannotationsfrom...coreimportModelofrom..calculations.registryimportCasillaId,register_cross_domain_snapshot_check
[docs]defcheck_first_slice_routing(modelo_id:str,casilla_ids:frozenset[CasillaId],renta_first_slice_binding_targets:frozenset[CasillaId],)->list[str]:"""Assert every casilla a revision's own first-slice bindings target exists on it. Returns a list of failure strings (empty when consistent). The registry validator prefixes each failure with the snapshot coordinates and raises a single ``RegistryValidationError``. """ifmodelo_id!=Modelo.M100:return[]missing=renta_first_slice_binding_targets-casilla_idsifnotmissing:return[]return[f"renta first-slice routing targets casillas {sorted(missing)!r} that are absent from the modelo-100 revision",]