Source code for cadrumo.domain.renta.retenciones_routing_integrity
"""Snapshot-time referential integrity for a registry-owned Renta route.The route declaration is authored in the governed registry mapping. Thismodule retains only the generic query projection and the cross-domain checkthat confirms a selected output endpoint exists before a consumer redirects aresolved value to it.The registry must not import the Renta domain directly. This module registersthe abstract snapshot check when the registry's snapshot builder imports thedeclared module, preserving the dependency direction while keeping the checkat the domain boundary."""from__future__importannotationsfromdataclassesimportdataclassfrom...core.casilla_idimportCasillaId,validated_casilla_idfrom...core.time.clockimporttoday_madridfrom..calculations.registry.facts.resolutionimportMappingFactQuery,ResolvedMappingFactfrom..calculations.registry.governed_fact_scopeimportGovernedFactSource,governed_facts_in_scopefrom..calculations.registry.idsimportBindingIdfrom..calculations.registry.schema_baseimportDateAxisfrom..calculations.registry.validate_cross_domain_snapshotimportregister_cross_domain_snapshot_check
[docs]@dataclass(frozen=True,slots=True)classM130RetencionesRoute:"""Generic typed projection of the selected registry route declaration."""modelo_id:strbinding_id:BindingIdoutput_casilla:CasillaId
# Registry authority: selected Renta binding routing is consumed through the governed mapping factdef_registry_m130_retenciones_route(*,authority:GovernedFactSource|None=None,)->M130RetencionesRoute:"""Resolve the selected route declaration without a Python fallback."""selected_authority=authorityorgoverned_facts_in_scope()ifselected_authorityisNone:raiseValueError("Renta route requires an explicit authority operation or scope")resolved=selected_authority.resolve_governed_fact(MappingFactQuery(fact_id="m130-retenciones-output-routing",date_axis=DateAxis.FILING_PERIOD,effective_date=today_madrid(),),)ifnotisinstance(resolved,ResolvedMappingFact):raiseTypeError("Renta route must resolve as a mapping fact")entries:dict[str,str]={}forentryinresolved.payload.entries:ifnotisinstance(entry.key,str)ornotisinstance(entry.value,str):raiseTypeError("Renta route entries must be string-to-string")ifentry.keyinentries:raiseValueError(f"duplicate Renta route key {entry.key!r}")entries[entry.key]=entry.value.strip()defrequired(key:str)->str:value=entries.get(key)ifvalueisNoneornotvalue:raiseValueError(f"Renta route is missing {key!r}")returnvaluereturnM130RetencionesRoute(modelo_id=required("modelo"),binding_id=required("binding_id"),output_casilla=validated_casilla_id(required("output_casilla"),surface="registry_renta_retenciones_route",),)
[docs]defresolve_m130_retenciones_route(*,authority:GovernedFactSource|None=None)->M130RetencionesRoute:"""Return the selected route for application-layer binding projection."""return_registry_m130_retenciones_route(authority=authority)
[docs]defcheck_m130_retenciones_output_casilla(modelo_id:str,casilla_ids:frozenset[CasillaId],renta_first_slice_binding_targets:frozenset[CasillaId],# shared Protocol shape, unused hererevision_binding_ids:frozenset[BindingId]=frozenset(),)->list[str]:"""Assert a selected route output endpoint exists when its binding is declared."""route=_registry_m130_retenciones_route()ifmodelo_id!=route.modelo_id:return[]ifroute.binding_idnotinrevision_binding_ids:return[]ifroute.output_casillaincasilla_ids:return[]return[f"selected revision declares binding {route.binding_id!r} but its "f"retenciones output casilla {route.output_casilla!r} ""is absent from the revision -- the resolved retencion would be written nowhere ""the filed form reads",]