Source code for cadrumo.domain.calculations.registry.concepto_ingreso
"""Typed projection of the governed income-concept vocabulary.The Art. 110 fact owns both the agrarian exclusion declaration and thecomplete receipt-concept vocabulary used by ledger rows. Keeping thevocabulary as a selector-scoped variant of that fact prevents a secondcanonical owner while allowing Art. 109 and Art. 110 to retain their distinctexclusion sets."""from__future__importannotationsfromdataclassesimportdataclassfromdatetimeimportdatefrom....core.concepto_ingresoimportConceptoIngresofrom....core.time.clockimporttoday_madridfrom.errorsimportRegistryValidationErrorfrom.facts.resolutionimportEntitySetFactQuery,ResolvedEntitySetFactfrom.facts.schemaimportFactSelectorfrom.governed_fact_scopeimportGovernedFactSource,cache_governed_projection,governed_facts_in_scopefrom.schema_baseimportDateAxis_FACT_ID="rd-439-2007-art-110:conceptos-ingreso-excluidos-volumen-agrario"_VOCABULARY_SELECTOR=FactSelector(name="scope",value="vocabulary")
[docs]@dataclass(frozen=True,slots=True)classConceptoIngresoCatalogue:"""Registry-declared income-concept tokens for transaction boundaries."""tokens:tuple[ConceptoIngreso,...]@propertydefall_tokens(self)->frozenset[ConceptoIngreso]:"""Return every token in the selected vocabulary."""returnfrozenset(self.tokens)
[docs]defrequire(self,value:object)->ConceptoIngreso:"""Return one token only when the selected fact declares it."""ifisinstance(value,ConceptoIngreso):token=valueelifisinstance(value,str):raw=value.strip()ifnotraw:raiseRegistryValidationError("income-concept token must be non-empty")try:token=ConceptoIngreso.from_registry(raw)except(TypeError,ValueError)asexc:raiseRegistryValidationError("income-concept token must be a non-empty string")fromexcelse:raiseRegistryValidationError("income-concept token must be a string token")iftokennotinself.all_tokens:raiseRegistryValidationError(f"income-concept token {str(token)!r} is not declared by fact {_FACT_ID!r}",)returntoken
def_resolve_catalogue(*,effective_date:date,authority:GovernedFactSource,)->ConceptoIngresoCatalogue:resolved=authority.resolve_governed_fact(EntitySetFactQuery(fact_id=_FACT_ID,date_axis=DateAxis.FILING_PERIOD,effective_date=effective_date,selectors=(_VOCABULARY_SELECTOR,),),)ifnotisinstance(resolved,ResolvedEntitySetFact):raiseRegistryValidationError("income-concept vocabulary must resolve as an entity-set fact")entities=tuple(sorted(str(entity).strip()forentityinresolved.payload.entities))ifnotentitiesorlen(entities)!=len(set(entities))orany(notentityforentityinentities):raiseRegistryValidationError("income-concept vocabulary must contain unique non-empty tokens")returnConceptoIngresoCatalogue(tokens=tuple(ConceptoIngreso.from_registry(entity)forentityinentities),)@cache_governed_projection(maxsize=64)def_bundled_catalogue(effective_date:date)->ConceptoIngresoCatalogue:deleffective_dateraiseRegistryValidationError("income-concept catalogue requires an explicit authority operation or scope")
[docs]defresolve_concepto_ingreso_catalogue(*,effective_date:date|None=None,authority:GovernedFactSource|None=None,)->ConceptoIngresoCatalogue:"""Resolve the selected dated income-concept vocabulary."""coordinate=effective_dateortoday_madrid()selected=authorityorgoverned_facts_in_scope()ifselectedisNone:return_bundled_catalogue(coordinate)return_resolve_catalogue(effective_date=coordinate,authority=selected)
[docs]defrequire_concepto_ingreso(value:object,*,effective_date:date|None=None,authority:GovernedFactSource|None=None,)->ConceptoIngreso:"""Project one receipt-concept token from the selected facts authority."""returnresolve_concepto_ingreso_catalogue(effective_date=effective_date,authority=authority,).require(value)