aeat.adapters.outbound.aeat.sede._parse module

Pure-function HTML parsers for the authenticated AEAT sede.

All parsers take raw HTML strings and return strict pydantic records. No Playwright, no I/O. This makes them trivially unit-testable against captured fixtures and keeps the navigation (side-effect) concerns isolated in adapters.outbound.aeat.sede._walker.

Public surface: parse_resumen_tree() (top-level expediente listing), parse_expediente_detail() (per-expediente CSV extraction).

parse_resumen_tree(html, *, base_url)[source]

Extract every expediente leaf from a ResumenVlt page.

The sede renders an AJAX-expanded category tree. After every relevant category has been expanded (by the walker), every expediente shows up as an <a> whose href points at one of AEAT’s per-filing-family endpoints and whose text is the expediente id.

Parameters:
  • html (str) – Full HTML body of the ResumenVlt page (post-expansion).

  • base_url (str) – The sede base URL (for resolving relative hrefs); typically "https://www6.agenciatributaria.gob.es".

Return type:

tuple[Expediente, ...]

Returns:

Tuple of Expediente records, one per discovered leaf. Order matches document order.

Raises:

SedeParseError – If the page has no category tree at all (the authenticated session likely expired).

parse_expediente_detail(html, *, expediente_id, base_url)[source]

Extract the CSV-keyed justificante handle from a detail page.

Captured live: every IRPF detail page (/wlpl/DASR-CORE/ AccesoDR<YYYY>RVlt) exposes the filed declaration via a Grabación de la declaración ... (Consulta / Copia) link that points at /wlpl/KATA-APLI/cotejo/CotejoIdSv?CSV=<csv>.

Parameters:
  • html (str) – Full HTML body of the expediente detail page.

  • expediente_id (str) – AEAT-assigned identifier (copied through onto the returned JustificanteRef).

  • base_url (str) – The sede base URL for absolutising the cotejo and PDF endpoints.

Return type:

JustificanteRef

Returns:

A JustificanteRef ready for capture_justificante().

Raises:

SedeParseError – If no CSV-carrying anchor is present.