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
Noneif the header does not yield both a modelo and an ejercicio. Revision resolution:If the PDF prints an
Orden HAC/N/YYYYfooter, use"{año}.orden-{N}".Else fall back to
"{ejercicio}.01".
The fallback is deliberately narrow: the registry must refuse any revision it has not explicitly registered.
The
Ejerciciostamp is searched across the first two pages of the header cluster — some Modelo 100 pre-2022 justificantes print theINFORMACIÓN DE LA PRESENTACIÓNcover page without theEjercicio YYYYline, deferring that marker to page 2.- Return type:
- Parameters:
pdf_path (Path)
- detect_template_revision_from_pages(pages)[source]¶
Return a
TemplateRevisionfrom already-extracted PDF page text.- Parameters:
pages (
tuple[str,...]) – Per-page text extracted from a declaración PDF.- Return type:
- Returns:
The detected
TemplateRevision, orNonewhen the header pages do not carry enough modelo/year signal.