aeat.adapters.inbound.declaracion._detect module

Template-revision detection for declaración PDFs.

AEAT prints the form code + año + period in a header / footer stamp. detect_template_revision peeks at the first page text; returns None on ambiguity so the caller can fall back to explicit --modelo --año flags. Detection resolves template identity only; the revision tag selects the registry declaracion_pdf extraction profile for the matched modelo and ejercicio.

The detector returns TemplateRevision records; it does not load RegistrySnapshot data or choose an extraction profile. Registry validation happens in parse_declaracion().

detect_template_revision(pdf_path)[source]

Peek at the PDF’s first page and return a TemplateRevision.

Returns None if the header does not yield both a modelo and an ejercicio. Revision resolution:

  1. If the PDF prints an Orden HAC/N/YYYY footer, use "{año}.orden-{N}".

  2. Else fall back to "{ejercicio}.01".

The fallback is deliberately narrow: the registry must refuse any revision it has not explicitly registered.

The Ejercicio stamp is searched across the first two pages of the header cluster — some Modelo 100 pre-2022 justificantes print the INFORMACIÓN DE LA PRESENTACIÓN cover page without the Ejercicio YYYY line, deferring that marker to page 2.

Return type:

TemplateRevision | None

Parameters:

pdf_path (Path)

detect_template_revision_from_pages(pages)[source]

Return a TemplateRevision from already-extracted PDF page text.

Parameters:

pages (tuple[str, ...]) – Per-page text extracted from a declaración PDF.

Return type:

TemplateRevision | None

Returns:

The detected TemplateRevision, or None when the header pages do not carry enough modelo/year signal.