aeat.application.workflow._engine module¶
Composition root for the end-user composite workflow engine.
WorkflowEngine walks the filing pipeline in strict linear order. Every
stage lives in its own small _stage_* method so the bailout matrix
is trivially auditable — a reader drops into a single stage method to
see exactly which abort reasons it can produce. The engine derives a
Schedule from the injected deadline adapter to gate the filing
window against the active obligation calendar.
Safety invariants enforced by this module:
The engine never touches AEAT-side state directly; every boundary call flows through an injected Protocol or callable seam.
- class WorkflowEngine(*, deadline_engine, filing_draft_builder, submission_engine, session, certificate_bundle, inputs_provider, settings, expedientes_source=None, notifications_source=None)[source]¶
Bases:
objectOrdered orchestrator across every AEAT building block.
Construction takes one Protocol handle per component. The authenticated AEAT session and the certificate bundle are optional: when
None, the stages that consume them run in skip mode and surface a diagnostic instead of failing.- Parameters:
deadline_engine (DeadlineEngineProtocol)
filing_draft_builder (ModeloDraftBuilderProtocol)
submission_engine (SubmissionEngineProtocol)
session (object | None)
certificate_bundle (CertificateBundleProtocol | None)
inputs_provider (ModeloInputsProviderProtocol)
settings (Settings)
expedientes_source (ExpedientesSource | None)
notifications_source (NotificationsSource | None)
- async run_next(profile, *, fail_on_warning=False, today=None)[source]¶
Drive the workflow for the caller’s next obligation.
- Parameters:
profile (
TaxpayerProfile) – TheTaxpayerProfileto run for.fail_on_warning (
bool) – Forwarded to the filing draft builder.today (
date|None) – Reference date for deadline / preflight checks. Defaults todate.today().
- Return type:
- Returns:
A fully populated
WorkflowResult.
- async run_for_period(profile, modelo, period, *, fail_on_warning=False, today=None, resumed_from=None, purpose=WorkflowPurpose.FILE)[source]¶
Drive the workflow for a caller-specified
(modelo, period).- Parameters:
profile (
TaxpayerProfile) – TheTaxpayerProfileto run for.modelo (
str) – Target modelo identifier.period (
Period) – Target period identifier.fail_on_warning (
bool) – Seerun_next().today (
date|None) – Seerun_next().resumed_from (
str|None) – Optional prior workflowrun_idthat this invocation continues. When set, the producedWorkflowResultcarries the linkage so callers can trace the resume chain. The engine does not validate the prior run by itself; the upstream resume action resolves and gates the prior context before invoking.purpose (
WorkflowPurpose) – Why the run is being driven.FILE(the default) treats the filing-window deadline as an abort gate;VERIFYrecords it as informational context and never aborts on it, so a calculation can be verified independently of the AEAT calendar.
- Return type:
- Returns:
A fully populated
WorkflowResult.- Raises:
WorkflowInputMismatchError – When
resumed_fromis supplied but is not a valid 16-character lowercase hex run id.