aeat.domain.invoices._validators module¶
Counterparty identity validators for invoice records.
The EU-IVA prefix check and ISO-3166 alpha-2 country-code normaliser
remain in this module because they are invoice-domain concerns.
Each helper raises ValueError on failure so pydantic
surfaces the error as a validation error in the enclosing
Invoice model.
The registry-grounded helpers
is_eu_member_state_code() and assert_eu_member_state_code()
anchor the EU axis to the substrate’s aeat.domain.iva.EUMemberState
enum. Modelo 369 binding selectors and the OSS / IOSS classifier
boundary checks consume these helpers so the EU membership decision
flows from the substrate, not from a hand-maintained list.
- EU_MEMBER_STATE_CODES: frozenset[str]¶
Closed set of ISO-3166 alpha-2 codes (uppercase) for the 27 EU Member States, sourced from
aeat.domain.iva.EUMemberStatewhile excluding the Northern Ireland IVA prefixXI.
- validate_country_code(value)[source]¶
Normalise and validate an ISO-3166 alpha-2 country code.
- Parameters:
value (
str) – Raw country code to validate.- Return type:
- Returns:
The uppercased two-letter country code.
- Raises:
InvoiceValidationError – If the input is not exactly two alphabetic characters.
- is_eu_member_state_code(value)[source]¶
Return
Truewhenvaluematches one of the 27 EU Member State codes.The membership check is anchored to
aeat.domain.iva.EUMemberState; if the substrate’s enum changes (Brexit-style additions or withdrawals) the helper picks up the new shape automatically.
- assert_eu_member_state_code(value)[source]¶
Validate
valueand assert it names an EU Member State.- Parameters:
value (
str) – Raw country code to validate.- Return type:
- Returns:
The uppercased two-letter EU Member State code.
- Raises:
InvoiceValidationError – If the input is malformed or names a non-EU country.
- validate_iva_number(value, country)[source]¶
Validate a non-ES IVA number shape against its country format.
For an EU Member State (and Northern Ireland
XI) the number is matched against the country’s published NIF-IVA structural pattern, sourced from the centralaeat.core.identity.NIF_IVA_FORMATSauthority: a malformed intra-community VAT number is bounced by AEAT’s Modelo 349 validator, so the refusal names the country and the expected format. Live VIES existence is not checked — only the structure. For a non-EU counterparty (no published pattern) the helper falls back to a generic leading-prefix plus 4-20 character alphanumeric body check, so non-EU counterparties remain acceptable.- Parameters:
- Return type:
- Returns:
The uppercased, whitespace-trimmed IVA identifier.
- Raises:
InvoiceValidationError – If the value is malformed, the prefix does not match
country, or the EU NIF-IVA format does not match.