"""Domain errors for the contribuyente tax-residence profile.Defines :class:`TaxResidenceProfileError` and its concrete failuressurfaced to RENTA verification, plus :class:`ProfileKeysRegistrationError`for the profile-key registry. The ledger error hierarchies live with theirrecords in :mod:`domain.contribuyente.assets` (asset) and:mod:`domain.contribuyente.inventory` (inventory and amortizacion). Everyclass derives from :class:`core.errors.AeatError` so the sharederror-code registration hook applies."""from__future__importannotationsfrom...core.errorsimportAeatError,CoreError
[docs]classTaxResidenceProfileError(AeatError):"""Base class for tax-residence profile failures. Concrete subclasses (:class:`ProfileNotConfiguredError`, :class:`ForalRegimeError`) carry their own translated messages and suggestions; this base type exists only so callers can catch the family with a single ``except`` clause. """
[docs]classProfileNotConfiguredError(TaxResidenceProfileError):"""Raised when RENTA verification needs a tax-residence profile. Attached to a ``suggestion`` pointing the operator at the profile edit wizard. """def__init__(self)->None:"""Build the multilingual no-profile-configured error."""super().__init__("No tax-residence profile is configured for RENTA.",translated_message="profile.errors.not_configured",suggestion="aeat config profile edit NAME --tax-residence-ccaa <ccaa>",)
[docs]classForalRegimeError(TaxResidenceProfileError):"""Raised when the user selects a foral regime not modelled by this profile. Attributes: value: The foral CCAA identifier supplied by the caller. """def__init__(self,value:str)->None:"""Build the multilingual foral-regime-out-of-scope error."""super().__init__(f"{value!r} is a foral regime outside the scope of this profile.",context={"tax_region":value},translated_message="profile.errors.foral_regime",)self.value=value
[docs]classProfileValidationError(TaxResidenceProfileError,ValueError):"""Raised when profile records violate state or shape invariants. Inherits from ValueError to maintain compatibility with Pydantic validators. """
[docs]classProfileKeysRegistrationError(CoreError):"""Raised on a profile-key registry invariant violation. Two cases share this typed exception (registered once centrally): a second registration with a conflicting tuple (the registry is single-writer, first registration wins), or an access before any registration — a programming / import-order error meaning the wizard catalogue (:mod:`application.wizard`) was not imported at startup to push the compiled keys via :func:`register_profile_keys`. Replaces a bare ``RuntimeError`` so callers can catch it precisely and the failure surfaces in the central registry. """def__init__(self,message:str="profile keys already registered with a different tuple")->None:"""Build the profile-keys registry-invariant error."""super().__init__(message,context={"registry":"profile._keys"},)