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:
walk_expedientes_tree()— listing traversal.resolve_justificante_ref()— expediente → CSV handle.capture_justificante()— expediente → authoritative PDF capture.
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 whenmodelois 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) – OptionalSettingsoverride. Defaults tocore.config.load_settings().
- Return type:
- Returns:
Tuple of
Expedienterecords, ordered as AEAT renders them (most recent first in every captured case so far).- Raises:
SedeNavigationError – If
gotoor 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_urlis used verbatim.
- Return type:
- Returns:
A
JustificanteRefready forcapture_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:
session (
AeatSession) – Authenticated session.expediente (
Expediente) – Target expediente.
- Return type:
- Returns:
A fully populated
SedeCapture.- Raises:
SedeNavigationError – On goto failures.
JustificanteFetchError – On PDF download failures.
- async find_expediente(session, *, modelo, ejercicio, settings=None)[source]¶
Convenience lookup: first expediente matching
(modelo, ejercicio).- Parameters:
- Return type:
- Returns:
The first
Expedientewhoseejerciciomatches.- Raises:
ExpedienteNotFoundError – If no expediente in the corpus matches the filter.