cadrumo.domain.deadlines.engine module¶
Registry-backed deadline computation engine.
Takes an TaxpayerProfile and a year and produces a deterministic,
typed Schedule. Filing windows and applicability conditions are
read from validated calculation registry data supplied by
ValidatedRegistryAuthority. Each window is described by a
ModeloRevision paired with its deadline window definitions.
- classify_obligation_status(closes_on, today, due_soon_days)[source]¶
Map a window close date to an
ObligationStatus.This is the single owner of the OVERDUE / DUE_TODAY / DUE_SOON / UPCOMING boundary rules. The deadline engine applies it to every registry-scheduled obligation, and the overview calendar applies it to a locally-created work unit after its own filing-pointer gate has run — that gate is the only intentional difference between the two callers, and it decides whether to call this function at all, never how the boundaries fall.
- Parameters:
- Return type:
- Returns:
The
ObligationStatusfor the window.
- indexed_deadline_windows(operation, year)[source]¶
Project one filing year’s deadline windows from a pinned operation.
Reused for a generation already projected for this year; see
_DEADLINE_WINDOW_INDEX.- Return type:
tuple[tuple[str,ModeloRevision,DeadlineWindowDefinition],...]- Parameters:
operation (PinnedAuthorityOperation)
year (int)
- class DeadlineEngine(*, due_soon_days=14, authority=None)[source]¶
Bases:
objectEngine that computes typed filing schedules from registry data.
- Variables:
due_soon_days – Window before
cadrumo.domain.deadlines.models.ModeloDeadline.closes_onthat flagscadrumo.domain.deadlines.models.ObligationStatus.DUE_SOON(default 14).- Parameters:
due_soon_days (int)
authority (PinnedAuthorityOperation | None)
- compute(profile, year, *, today=None)[source]¶
Compute the full
Scheduleforprofilexyear.Pure function: no I/O, no input mutation. Identical
(profile, year, today)always yields an equal schedule (moduloSchedule.generated_at).- Parameters:
profile (
TaxpayerProfile) – TheTaxpayerProfileto compute obligations for.year (
int) – The fiscal year to compute for.today (
date|None) – Reference date for status classification. Defaults to the canonical Europe/Madrid civil date returned bycadrumo.core.time.clock.today_madrid().
- Return type:
- Returns:
The
Schedulecontaining every obligation that applies toprofileforyear.- Raises:
NoDeadlineWindowsError – If no validated registry deadline windows are registered for
year— the benign data gap callers degrade around.
- explain(profile, modelo, *, year=None)[source]¶
Return registry-backed deadline applicability text for
modelo.- Parameters:
profile (
TaxpayerProfile) – TheTaxpayerProfileto evaluate conditions against.modelo (
str) – The AEAT modelo identifier to look up.year (
int|None) – Optional fiscal year; defaults to the current year.
- Return type:
- applies_to(profile, modelo, *, year=None)[source]¶
Return whether registry deadline conditions match for
modelo.- Parameters:
profile (
TaxpayerProfile) – TheTaxpayerProfileto evaluate conditions against.modelo (
str) – The AEAT modelo identifier to check.year (
int|None) – Optional fiscal year; defaults to the current year.
- Return type:
- deadline_windows(year)[source]¶
Return validated registry deadline windows for
year.This read-only facade lets application projections inspect the same registry surface used by
compute()without reaching into engine implementation details.- Return type:
tuple[tuple[str,ModeloRevision,DeadlineWindowDefinition],...]- Parameters:
year (int)
- schedule_applies(profile, revision, window)[source]¶
Return whether a validated filing schedule applies to
profile.- Parameters:
profile (
TaxpayerProfile) – TheTaxpayerProfilewhose declared facts are checked against the schedule.revision (
ModeloRevision) – TheModeloRevisionwhose filing schedules are consulted.window (
DeadlineWindowDefinition) – The deadline window under evaluation.
- Return type:
- evaluate_conditions(profile, conditions, *, mode)[source]¶
Evaluate one registry applicability-condition tuple.
- Parameters:
profile (
TaxpayerProfile) – TheTaxpayerProfilethe conditions are checked against.conditions (
tuple[ProfilePredicateDefinition,...]) – The registry-declared predicate tuple to evaluate.mode (
str) – The evaluation mode forwarded to the registry evaluator.
- Return type:
- next_deadline(schedule, today=None)[source]¶
Return the next obligation in
schedulethat has not yet closed.Pure function. Returns
Noneif every obligation in the schedule is already overdue (or the schedule is empty).- Parameters:
schedule (
Schedule) – TheScheduleto scan for upcoming obligations.today (
date|None) – Reference date. Defaults to the canonical Europe/Madrid civil date returned bycadrumo.core.time.clock.today_madrid().
- Return type:
- Returns:
The earliest non-overdue
ModeloDeadline, orNoneif no such obligation exists.
- class ScheduleProducer(*args, **kwargs)[source]¶
Bases:
ProtocolStructural surface over
DeadlineEngine.compute.compute_obligation_schedule()is typed against this Protocol rather than the concreteDeadlineEngineso the workflow engine — which injects a protocol-typed deadline engine — and the state projection — which uses a concreteDeadlineEngine— can both feed the same single-producer function.- compute(profile, year, *, today=None)[source]¶
Return a
Scheduleforprofileinyear.- Parameters:
profile (
TaxpayerProfile) – TheTaxpayerProfileto compute obligations for.year (
int) – The fiscal year to compute for.today (
date|None) – Reference date for status classification.
- Return type:
- compute_obligation_schedule(engine, profile, *, today)[source]¶
Compute the obligation
Schedulefrom one canonical call.This is the single producer of the pending-obligation datum. Both the operator state read-projection (
pending_obligations) and theWorkflowEngineNO_PENDING_OBLIGATIONgate route their schedule computation through here, so the gate and the projection cannot draw a divergent obligation set: identical(engine, profile, today)always yields an equal schedule (moduloSchedule.generated_at).The fiscal year is derived from
todayso neither consumer can pass a mismatched(year, today)pair.- Parameters:
engine (
ScheduleProducer) – The deadline engine to compute with. AnyScheduleProducer— a concreteDeadlineEngineor the workflow engine’s protocol-typed injected deadline engine.profile (
TaxpayerProfile) – TheTaxpayerProfileto schedule obligations for.today (
date) – Reference date; the fiscal year and obligation status classification are both derived from it.
- Return type:
- Returns:
The
Scheduleof obligations applicable toprofilefortoday’s fiscal year.
- applies_to(profile, modelo)[source]¶
Return whether registry deadline conditions match for
modelo.- Parameters:
profile (
TaxpayerProfile) – TheTaxpayerProfileto evaluate conditions against.modelo (
str) – The AEAT modelo identifier to check.
- Return type:
- explain(profile, modelo)[source]¶
Return registry-backed deadline applicability text for
modelo.- Parameters:
profile (
TaxpayerProfile) – TheTaxpayerProfileto evaluate conditions against.modelo (
str) – The AEAT modelo identifier to look up.
- Return type: