aeat.adapters.outbound.aeat.sede._walker module

Playwright-driven sede walker: session → expedientes → PDF bytes.

The walker is the only side-effectful layer in adapters.outbound.aeat.sede. It takes an AeatSession whose encrypted browser state carries valid AEAT cookies, drives a read-only Playwright session over the sede, and exposes three operations to callers:

All three are read-only by construction: only page.goto and context.request.get cross the wire. No click() onto submit buttons, no form POSTs, no mutation verbs anywhere in the public surface.

async walk_expedientes_tree(session, *, modelo=None, settings=None)[source]

Enumerate every expediente visible under Mis Expedientes.

The sede renders an AJAX-expanded tree. This function expands every category branch whose label contains a Modelo <N> token (or all branches when modelo is None), then parses the resulting DOM for leaf expediente rows.

Parameters:
  • session (AeatSession) – An authenticated session with encrypted cached AEAT cookies. Cl@ve-móvil and certificate sessions both qualify.

  • modelo (str | None) – When set, only expand category branches whose label references this modelo code (e.g. "100" for IRPF). Saves DOM expansion work on large corpora.

  • settings (Settings | None) – Optional Settings override. Defaults to core.config.load_settings().

Return type:

tuple[Expediente, ...]

Returns:

Tuple of Expediente records, ordered as AEAT renders them (most recent first in every captured case so far).

Raises:

SedeNavigationError – If goto or a required expansion fails.

async resolve_justificante_ref(session, expediente, *, settings=None)[source]

Navigate to an expediente’s detail page and extract its CSV ref.

Parameters:
  • session (AeatSession) – Authenticated session with encrypted cached AEAT cookies.

  • expediente (Expediente) – Expediente to look up. expediente.detail_url is used verbatim.

  • settings (Settings | None) – Optional override.

Return type:

JustificanteRef

Returns:

A JustificanteRef ready for capture_justificante().

Raises:

SedeNavigationError – If the detail page cannot be loaded.

async capture_justificante(session, expediente, *, settings=None)[source]

End-to-end: expediente → CSV handle → PDF bytes → SedeCapture.

Bundles resolve_justificante_ref() + the raw PDF GET into one session-reusing call. The preferred entry point for callers that just want “the AEAT record for this expediente”.

Parameters:
Return type:

SedeCapture

Returns:

A fully populated SedeCapture.

Raises:
async find_expediente(session, *, modelo, ejercicio, settings=None)[source]

Convenience lookup: first expediente matching (modelo, ejercicio).

Parameters:
  • session (AeatSession) – Authenticated AEAT session.

  • modelo (str) – Modelo code to filter on (e.g. "100").

  • ejercicio (int) – Tax year to match.

  • settings (Settings | None) – Optional Settings override.

Return type:

Expediente

Returns:

The first Expediente whose ejercicio matches.

Raises:

ExpedienteNotFoundError – If no expediente in the corpus matches the filter.