Source code for aeat.domain.iva._errors

"""Domain errors for the :mod:`aeat.domain.iva` subpackage.

Every failure mode raised by the IVA substrate inherits from
:class:`IvaError`, which in turn inherits from
:class:`aeat.core.errors.AeatError`. Downstream callers catch the base class
when they want to treat the substrate as an opaque unit, or the specific
subclass when they need to distinguish missing-rate from missing-category or
corpus load failures.
"""

from __future__ import annotations

from ...core.errors import AeatError


[docs] class IvaError(AeatError): """Base error for every :mod:`aeat.domain.iva` failure mode."""
[docs] class IvaRateNotFoundError(IvaError): """Raised when :func:`aeat.domain.iva.lookup_rate` cannot resolve a rate. The lookup fails either because the requested member state is absent from :data:`aeat.domain.iva.IVA_RATE_TABLE`, because no rate of the requested :class:`aeat.domain.iva.IvaRateKind` is registered for that member state, or because every registered rate's effective window excludes the requested date. """
[docs] class IvaCategoryNotFoundError(IvaError): """Raised when a lookup against a resolved IVA catalogue misses."""
[docs] class IvaCatalogueError(IvaError): """Raised when a IVA catalogue cannot be loaded, resolved, or validated."""
[docs] class IvaRateOverlapError(IvaError): """Raised when two :class:`aeat.domain.iva.IvaRateRecord` records share a window. The substrate enforces that for every ``(member_state, kind)`` partition of :data:`aeat.domain.iva.IVA_RATE_TABLE` no two records have overlapping ``effective_from`` / ``effective_until`` ranges. Adding a new record that violates this invariant raises this error at module import time so the regression surfaces in CI rather than silently affecting :func:`aeat.domain.iva.lookup_rate` results. """
[docs] class IvaClassificationError(IvaError): """Raised when :func:`aeat.domain.iva.classify_iva` cannot return a deterministic match. The classifier exposes a closed first-match-wins table; the only structural failure is when the input criteria cannot be represented under the closed enum set, which is caught at construction time by pydantic. This error is reserved for future extensions such as ambiguous rule rankings. """
[docs] class IvaValidationError(IvaError, ValueError): """Raised on invalid IVA field values. Inherits from ValueError for Pydantic."""
[docs] class ProrrataError(IvaError): """Base error for IVA prorrata calculation failures (LIVA arts. 101-103)."""
[docs] class ProrrataInputError(ProrrataError, ValueError): """Raised when prorrata inputs violate domain invariants. Inherits from ``ValueError`` so pydantic surfaces it as a ``ValidationError`` when raised from a model validator. """
[docs] class ProrrataSectorError(ProrrataError): """Raised when sectoral-separation inputs are inconsistent. Examples: a sector references an unknown id, two sectors share an activity code, or the sector list is empty when sectoral separation is required (LIVA art. 9.1.c). """