aeat.adapters.inbound.declaracion._parser module

Public parse_declaracion entry points for declaration-copy PDFs.

Parsing is registry-profile-driven: template detection resolves the modelo/year/revision coordinate, then a RegistrySnapshot supplies the single declaracion_pdf ExtractionProfileDefinition used to extract casillas. There is deliberately no per-modelo extractor class registry here.

When callers do not supply a snapshot, the parser loads one through ValidatedRegistryAuthority. The snapshot’s ModeloRevision owns the canonical casilla declarations and the returned InboundDeclaracionObservation stamps the exact RegistrySnapshotRef. The bytes entry point keeps decrypted live-read PDF content in memory rather than materialising a plaintext temporary file.

parse_declaracion(pdf_path, *, modelo_override=None, template_revision_override=None, año_override=None, period_override=None, extraction_profile_id=None, registry_snapshot=None, registry_root=None, source_root=None)[source]

Parse an AEAT declaración PDF into a InboundDeclaracionObservation.

Use this filesystem entry point when the declaration copy is already on disk. The observation carries a digest-backed PDF source reference and a RegistrySnapshotRef so downstream filing checks can identify the registry coordinate that interpreted the printed values.

Parameters:
  • pdf_path (Path) – Path to the declaración PDF.

  • modelo_override (str | None) – Explicit modelo identifier (skips detection).

  • template_revision_override (str | None) – Explicit revision string (skips detection).

  • año_override (int | None) – Explicit four-digit tax year (skips detection).

  • period_override (str | None) – Explicit printed period when the PDF text does not expose a stable period marker.

  • extraction_profile_id (str | None) – Registry extraction profile to use when the selected snapshot contains more than one declaration-PDF profile.

  • registry_snapshot (RegistrySnapshot | None) – Pre-built validated RegistrySnapshot. When omitted, the parser loads the committed registry and builds one from the detected modelo, tax year, and period.

  • registry_root (Path | None) – Optional registry TOML root used when registry_snapshot is omitted.

  • source_root (Path | None) – Optional source root used for source integrity checks while building a snapshot.

Return type:

InboundDeclaracionObservation

Returns:

A strict InboundDeclaracionObservation populated with the extracted casillas, warnings, and provenance metadata.

Raises:

DeclaracionParseError – When text extraction, template/period detection, registry snapshot loading, or registry-profile extraction fails.

parse_declaracion_bytes(pdf_bytes, *, source_label='in-memory declaracion PDF', modelo_override=None, template_revision_override=None, año_override=None, period_override=None, extraction_profile_id=None, registry_snapshot=None, registry_root=None, source_root=None)[source]

Parse declaración PDF bytes without writing them to a plaintext temp file.

This is the live-read path for already-decrypted artefacts. Page text and bbox word extraction operate on the supplied bytes, and the observation uses a digest-derived source reference instead of a real filesystem path.

Parameters:
  • pdf_bytes (bytes) – Raw PDF bytes to parse.

  • source_label (str) – Label identifying the in-memory source for log messages.

  • modelo_override (str | None) – Explicit modelo identifier (skips detection).

  • template_revision_override (str | None) – Explicit revision string (skips detection).

  • año_override (int | None) – Explicit four-digit tax year (skips detection).

  • period_override (str | None) – Explicit printed period when the PDF text does not expose a stable period marker.

  • extraction_profile_id (str | None) – Registry extraction profile to use when the selected snapshot contains more than one declaration-PDF profile.

  • registry_snapshot (RegistrySnapshot | None) – Pre-built validated RegistrySnapshot. When omitted, the parser loads the committed registry and builds one from the detected modelo, tax year, and period.

  • registry_root (Path | None) – Optional registry TOML root used when registry_snapshot is omitted.

  • source_root (Path | None) – Optional source root used for source integrity checks while building a snapshot.

Return type:

InboundDeclaracionObservation

Returns:

A InboundDeclaracionObservation populated with the extracted casillas, warnings, and provenance metadata.

Raises:

DeclaracionParseError – When text extraction, template/period detection, registry snapshot loading, or registry-profile extraction fails.