aeat.adapters.inbound.justificante._parser module

Inbound parse_justificante entry points.

This thin orchestration layer pairs a text backend selected by JustificanteParserBackend with the regex extractor in adapters.inbound.justificante._extract. The extractor turns AEAT receipt text into a strict Justificante; casilla-complete declaration PDFs are intentionally out of scope for this adapter.

The filesystem route hashes the PDF before extraction. The bytes route is for secure-storage or live-capture flows that already hold decrypted bytes and must avoid plaintext temporary files. Both routes surface structured JustificanteParseError attributes for missing, malformed, ambiguous, and coverage-related failures.

parse_justificante(pdf_path, *, backend=None)[source]

Parse an AEAT justificante PDF into a strict Justificante.

Use this filesystem entry point when the receipt PDF is already on disk. The downstream extractor stores a digest-derived source reference on the returned Justificante, while parser-boundary failures redact the caller-controlled path from user-facing error messages.

Parameters:
Return type:

Justificante

Returns:

A fully populated Justificante pydantic v2 record.

Raises:

JustificanteParseError – If the file is missing, cannot be opened, or does not contain the required fields.

parse_justificante_bytes(pdf_bytes, *, backend=None)[source]

Parse an AEAT justificante PDF already loaded from secure storage.

The PDF bytes are hashed in memory and passed directly to the configured backend, so decrypted live-capture content does not need a plaintext temporary file.

Parameters:
Return type:

Justificante

Returns:

The parsed Justificante extracted from the PDF bytes.

Raises:

JustificanteParseError – If no extractable receipt text or required receipt fields can be read.