Source code for cadrumo.application.user_profile.filing_baseline
"""Filing-grade profile identity baseline checks."""from__future__importannotationsfromcollections.abcimportMappingfrom...domain.contribuyente.entity_typeimport(entity_type_attribution_entity_token,entity_type_legal_entity_token,)from.completenessimportconditional_profile_missing_requireddef_identity_baseline_flags(values:Mapping[str,object])->tuple[str,...]:"""Return the identity flags this entity type owes, ignoring conditionals."""missing:list[str]=[]entity_type=_profile_token(values,"taxpayer_type.entity_type")ifnotentity_type:missing.append("entity-type")ifentity_type==entity_type_legal_entity_token().value:ifnot_profile_token(values,"taxpayer_type.legal_entity_form"):missing.append("legal-entity-form")ifnot_profile_token(values,"identity.legal_name"):missing.append("legal-name")returntuple(missing)ifentity_type==entity_type_attribution_entity_token().value:ifnot_profile_token(values,"identity.name"):missing.append("name")returntuple(missing)ifnot_profile_token(values,"identity.name"):missing.append("name")ifnot_profile_token(values,"identity.surnames"):missing.append("surnames")returntuple(missing)
[docs]defmissing_filing_baseline_flag_groups(values:Mapping[str,object],*,profile_path_flags:Mapping[str,str],)->tuple[tuple[str,...],tuple[str,...]]:"""Return the missing flags split into identity and conditional groups. Both groups block the same write, but they are different obligations and reporting them under one message misdescribed whichever group the operator actually hit: a profile lacking only the Modelo 303 IVA block was told its "identity data" was incomplete while its name and NIF were plainly set. Identity takes precedence where the two overlap. The conditional resolver also demands the legal-entity fields once the entity type is a legal entity, so subtracting the conditional set instead would empty the identity group and report a missing legal name as a Modelo 303 requirement. """identity=tuple(dict.fromkeys(_identity_baseline_flags(values)))identity_set=set(identity)conditional=tuple(flagforflagindict.fromkeys(_profile_path_flag(path,profile_path_flags=profile_path_flags)forpathinconditional_profile_missing_required(values))ifflagnotinidentity_set)returnidentity,conditional
def_profile_path_flag(path:str,*,profile_path_flags:Mapping[str,str])->str:"""Return the long-option spelling for a profile path. The refusal that carries this names flags the operator retypes verbatim, so a dotted path must never reach it: this CLI's operator is an autonomous agent that follows the instruction literally and cannot recover from a flag that does not parse. An unregistered path falls back to a dash form, which may be the wrong flag but is at least a well-formed one. """registered=profile_path_flags.get(path)ifregisteredisnotNone:returnregisteredreturnpath.replace(".","-").replace("_","-")def_profile_token(values:Mapping[str,object],path:str)->str:returnstr(values.get(path)or"").strip()__all__=["missing_filing_baseline_flag_groups"]