aeat.adapters.inbound.justificante._extract module¶
Regex-driven field extraction for AEAT justificante receipt PDFs.
This module translates the raw text of a justificante (as returned by one of
the backends in adapters.inbound.justificante._parsers) into a
Justificante pydantic record. It extracts
receipt metadata only: CSV, modelo, period/ejercicio, taxpayer, presentation
timestamp, optional payment totals, and the verification URL. Casilla-level
filing values belong to the declaración/borrador adapters, not this receipt
surface.
The regex patterns deliberately accept both accented (“Código Seguro de Verificación”) and stripped (“Codigo Seguro de Verificacion”) label variants because AEAT’s historical PDF corpus mixes the two depending on the year and font embedding.
The extractor is deterministic: same input bytes produce the same output
record. All monetary values are parsed via decimal.Decimal to
preserve the receipt precision; never floats. Parse failures populate the
structured attributes on
JustificanteParseError so callers and tests
do not need to parse message strings.
- extract_justificante(text, pdf_path)[source]¶
Extract a
Justificantefrom the raw text of a receipt PDF.This path-based helper computes the PDF digest itself before delegating to
extract_justificante_from_digest.- Parameters:
text (
str) – Full concatenated text returned by a parser backend.pdf_path (
Path) – Path of the source PDF (used to compute the privacy-preservingsource_pdf_pathreference and sha-256 digest).
- Return type:
- Returns:
A fully populated
Justificanterecord.- Raises:
JustificanteParseError – If any required field is missing or cannot be coerced into its target type.
- extract_justificante_from_digest(text, *, source_pdf_sha256, source_label='<input-pdf>')[source]¶
Extract a
Justificantewhen the caller already has the PDF digest.The digest is converted into the persisted
source_pdf_pathreference, so callers that parse bytes from secure storage can retain provenance without writing those bytes to disk.- Raises:
JustificanteParseError – If receipt text is empty, a required field is missing, a captured value is malformed, or the final strict record fails validation.
- Return type:
- Parameters: