Source code for cadrumo.application.modelo.m303_regimen_simplificado_scope
"""Secure-profile scope resolution for the M303 simplified-regime branch."""from__future__importannotationsfromcollections.abcimportMappingfrom...core.operator_action_enumsimportActionEvidenceProvenancefrom...domain.calculations.registry.errorsimportRegistryValidationErrorfrom...domain.calculations.registry.iva_schema_vocabularyimport(m303_regime_composition_simplified_scope,)from...domain.deadlines.modelsimportM303RegimeComposition,TaxpayerProfilefrom...domain.iva.regimen_simplificado_rowsimportM303RegimenSimplificadoScopeDecisionfrom...domain.modelos.work_unitimportWorkUnitfrom...domain.user_profile.valuesimportProfileSetupStatefrom..user_profile.projectionsimportprojection_for_taxpayerfrom.action_errorsimportModeloProfileReadinessErrorfrom.preconditionsimportModeloPreconditionFailure,build_modelo_precondition_failure_for_scenariofrom.profile_readiness_gateimportload_modelo_work_profilefrom.work_profileimportModeloWorkProfile_READINESS_SUBJECT_LEAF_KEY="modelo.work.calculate"_READINESS_SCENARIO_PREFIX="modelo.work.calculate.m303_profile_readiness"
[docs]defm303_profile_readiness_failure(scenario_code:str,evidence_values:Mapping[str,str|int|bool],)->ModeloPreconditionFailure:"""Return the declared failure for one Modelo 303 profile-readiness scenario."""returnbuild_modelo_precondition_failure_for_scenario(subject_leaf_key=_READINESS_SUBJECT_LEAF_KEY,scenario_id=f"{_READINESS_SCENARIO_PREFIX}.{scenario_code}",evidence_id=f"{_READINESS_SCENARIO_PREFIX}.{scenario_code}.observation",evidence_values=evidence_values,provenance=ActionEvidenceProvenance.APPLICATION_STATE,)
[docs]defactive_taxpayer_profile(work_unit:WorkUnit)->TaxpayerProfile:"""Load the work unit's active, setup-complete taxpayer profile, or raise."""from...domain.calculations.registry.authorityimportbundled_indexed_authoritywithbundled_indexed_authority().operation()asoperation:profile=load_modelo_work_profile(bucket_id=work_unit.bucket_id,profile_decode_context=operation.profile_decode_context(),)returntaxpayer_profile_for_work(profile)
[docs]deftaxpayer_profile_for_work(profile:ModeloWorkProfile|None)->TaxpayerProfile:"""Project an already-loaded work profile, refusing an absent or incomplete one."""ifprofileisNone:raiseModeloProfileReadinessError(precondition_failure=m303_profile_readiness_failure("profile_absent",{"profile_present":False}),)record=profile.recordifrecord.setup_stateisnotProfileSetupState.COMPLETE:raiseModeloProfileReadinessError(precondition_failure=m303_profile_readiness_failure("profile_inactive",{"profile_present":True,"profile_setup_state":str(record.setup_state)},),)returnprojection_for_taxpayer(record,schema=profile.profile_decode_context.schema)
[docs]defm303_regimen_simplificado_scope_for_profile(profile:TaxpayerProfile,)->M303RegimenSimplificadoScopeDecision:"""Map the canonical secure IVA profile composition to the closed simplified-regime scope. Core types: :class:`~cadrumo.domain.deadlines.models.TaxpayerProfile`. """iva_profile=profile.ivaifiva_profileisNone:raiseModeloProfileReadinessError(precondition_failure=m303_profile_readiness_failure("iva_composition_missing",{"iva_profile_present":False},),)returnm303_regimen_simplificado_scope_for_composition(iva_profile.regime_composition)
[docs]defm303_regimen_simplificado_scope_for_composition(composition:M303RegimeComposition|str,)->M303RegimenSimplificadoScopeDecision:"""Map one registry-projected IVA composition to its registry-projected scope."""try:scope=m303_regime_composition_simplified_scope(composition)exceptRegistryValidationErrorasexc:raiseModeloProfileReadinessError(precondition_failure=m303_profile_readiness_failure("iva_composition_unknown",{"iva_profile_present":True,"regime_composition":str(composition)},),)fromexcreturnM303RegimenSimplificadoScopeDecision(scope=scope,)
[docs]defm303_regimen_simplificado_annual_summary_applies(work_unit:WorkUnit)->bool:"""Return whether regimen simplificado reaches this work unit's taxpayer. The single derivation the Modelo 390 annual-summary guard, resolver, and persisted-handoff validator all consult, so one taxpayer cannot be judged applicable by one and not another. Boxes 74--83 ride on every Modelo 390 form, so a revision declaring that binding family says what the FORM carries and never that the regime reaches this filer: LIVA art. 122 Uno applies regimen simplificado only to sujetos pasivos meeting its three stated requirements. """returnm303_regimen_simplificado_annual_summary_applies_to_profile(active_taxpayer_profile(work_unit))
[docs]defm303_regimen_simplificado_annual_summary_applies_to_profile(profile:TaxpayerProfile)->bool:"""The same derivation as :func:`m303_regimen_simplificado_annual_summary_applies`, on a loaded profile. Core types: :class:`~cadrumo.domain.deadlines.models.TaxpayerProfile`. """returnnotm303_regimen_simplificado_scope_for_profile(profile).is_not_claimed