Source code for cadrumo.domain.calculations.registry.prorrata_regularizacion_bindings
"""The annual prorrata regularisation provider and its landing casillas."""from__future__importannotationsfromcollections.abcimportIterablefromenumimportStrEnumfromtypingimportLiteral,ProtocolfrompydanticimportBaseModel,field_validatorfrom....core.aggregationimportBindingSourceKindfrom....core.casilla_idimportCasillaId,validated_casilla_idfrom....core.errors.hierarchyimportpydantic_validation_boundaryfrom....core.modelsimportSTRICT_FROZEN_CONFIGfrom.errorsimportRegistryValidationError__all__=["ProrrataRegularizacionOutput","ProrrataRegularizacionOutputValue","ProrrataRegularizacionProvider","prorrata_source_casilla_ids",]class_BindingWithProvider(Protocol):@propertydefprovider(self)->object:"""Return the binding's typed provider declaration."""...
[docs]defprorrata_source_casilla_ids(bindings:Iterable[_BindingWithProvider])->tuple[CasillaId,...]:"""Return the unique, declared prorrata source casillas in registry order."""ids:list[CasillaId]=[]forbindinginbindings:ifnotisinstance(binding.provider,ProrrataRegularizacionProvider):continueforcasilla_idinbinding.provider.source_casilla_ids:value=validated_casilla_id(casilla_id,surface="selected prorrata source casilla")ifvaluenotinids:ids.append(value)returntuple(ids)
[docs]classProrrataRegularizacionOutput(StrEnum):"""Which casilla a prorrata regularizacion lands in."""MODELO_303_CASILLA_44="modelo_303_casilla_44"MODELO_390_REGULARIZACION_ANUAL="modelo_390_regularizacion_anual"
ProrrataRegularizacionOutputValue=Literal[ProrrataRegularizacionOutput.MODELO_303_CASILLA_44,ProrrataRegularizacionOutput.MODELO_390_REGULARIZACION_ANUAL,]"""The same vocabulary for a strict model field."""_PRORRATA_REGULARIZACION_SOURCE_IDS:tuple[CasillaId,...]=("iva.cuota-deducible-total","iva.prorrata-volumen-con-derecho","iva.prorrata-volumen-total","iva.prorrata-porcentaje",)_PRORRATA_REGULARIZACION_SOURCE_PERIODS:tuple[str,...]=("1T","2T","3T","4T")
[docs]classProrrataRegularizacionProvider(BaseModel):"""Selector for annual prorrata regularisation filing targets."""model_config=STRICT_FROZEN_CONFIGkind:Literal[BindingSourceKind.PRORRATA_REGULARIZACION]=BindingSourceKind.PRORRATA_REGULARIZACIONsource_modelo:Literal["303"]source_casilla_ids:tuple[CasillaId,...]source_periods:tuple[str,...]regularizacion_output:ProrrataRegularizacionOutputValue@field_validator("source_casilla_ids")@classmethod@pydantic_validation_boundarydef_source_casilla_ids_match_prorrata_inputs(cls,value:tuple[CasillaId,...])->tuple[CasillaId,...]:ifvalue!=_PRORRATA_REGULARIZACION_SOURCE_IDS:raiseRegistryValidationError("prorrata_regularizacion selector must declare the Modelo 303 deductible-total, ""annual prorrata volume, and definitive-percentage casilla ids in canonical order",)returnvalue@field_validator("source_periods")@classmethod@pydantic_validation_boundarydef_source_periods_are_full_year(cls,value:tuple[str,...])->tuple[str,...]:ifvalue!=_PRORRATA_REGULARIZACION_SOURCE_PERIODS:raiseRegistryValidationError("prorrata_regularizacion selector must declare source_periods ('1T', '2T', '3T', '4T')",)returnvalue