aeat.domain._identifiers module

Shared validating identifiers and hash-payload primitives.

Provides ModeloIdentifier for modelo-code shape validation and canonical_decimal_string() for hash-stable decimal payloads. Invalid modelo-code shapes raise DomainValidationError, matching the domain validation contract used by Pydantic-backed records.

This module is deliberately narrower than the registry-backed modelo catalogue. ModeloIdentifier preserves leading zeros and validates the textual identifier shape only; it does not prove that a modelo is present in the bundled registry or in the closed core.Modelo enum. Callers that need a loadable revision must ask the registry authority.

class ModeloIdentifier(value)[source]

Bases: str

Typed string identifier for the textual AEAT modelo-code shape.

The type preserves the incoming string and accepts three digits plus an optional uppercase suffix. It is suitable for lightweight domain records and Pydantic schemas that need syntactic validation without importing the registry authority. It is not a membership check against the current registry or the closed core.Modelo enum.

Parameters:

value (str)

Return type:

ModeloIdentifier

canonical_decimal_string(value)[source]

Render a Decimal into a stable fixed-point string for hashing.

Used by domain derive_*_id helpers to canonicalise monetary fields before they enter a SHA-256 hash payload, so two semantically equal amounts (Decimal("10") vs Decimal("10.00")) hash to the same identifier. Zero collapses to "0" regardless of input precision; non-zero values are normalised (trailing zeros removed) and formatted without exponent notation.

This helper does not round, quantize, localize, or format amounts for display. Callers that need a legal scale or currency presentation must enforce that contract before or after using this hash-normalization helper.

Return type:

str

Parameters:

value (Decimal)