cadrumo.application.overview.calendar module¶
Calendar aggregation and evidence merge for the overview read model.
The facade composes a Schedule from
TaxpayerProfile facts and projects
already-loaded local state into OverviewCalendar DTOs. Legal
obligation rows come from the deadline engine; observed
OverviewCalendarEvent rows and OverviewCalendarFilingEvidence
rows come from persisted Modelo records, local live-read snapshots, and
loaded justificante metadata supplied by the caller.
This module is local-only and pure with respect to I/O: it never starts a
live AEAT read and never verifies a justificante by fetching external
state. It only reconciles evidence the storage or CLI layer has already
loaded, preserving distinct OverviewLocalFilingState and
OverviewAeatSubmissionState axes.
See also
cadrumo.application.overview.calendar_modelsDefines the calendar DTOs returned by these builders.
DeadlineEngineDeadline authority that produces the legal obligation schedule merged into the overview calendar.
calendar_filing_evidence_from_sources()Pure evidence merge for local filing records, live captures, filed-declaration observations, and loaded justificante metadata.
JustificanteCaptureSnapshotPersisted live justificante capture projected as AEAT-side evidence only when matching metadata is already loaded.
ModeloRecordLocal filing record projected on the local filing axis, separate from AEAT submission state.
- calendar_events_from_expedientes_snapshots(snapshots, calendar_range, *, expected_tax_id=None)[source]¶
Project persisted declaration-register snapshots into calendar events.
Each in-range declaration becomes an
OverviewCalendarEventwhen its authenticated identity matchesexpected_tax_id. Only activeALTArows carryOverviewAeatSubmissionState.SUBMITTED_OBSERVED; non-active rows remain historical events and cannot upgradeOverviewCalendarFilingEvidence.- Return type:
- Parameters:
snapshots (tuple[PersistedExpedientesSnapshot, ...])
calendar_range (_OverviewCalendarRange)
expected_tax_id (str | None)
- calendar_events_from_notification_snapshots(snapshots, calendar_range, *, as_of, expected_tax_id=None)[source]¶
Project persisted AEAT notifications into message events.
Notifications become
OverviewCalendarEventType.MESSAGErows only; they are additive calendar observations and never implyOverviewAeatSubmissionStateor filing evidence for an obligation.Each row also carries its
NotificacionEstadoServicioservice state, computed againstas_ofso a projection over stored snapshots is reproducible rather than dependent on when it happened to run.- Parameters:
snapshots (
tuple[PersistedNotificationsSnapshot,...]) – Persisted notification snapshots loaded by the caller.calendar_range (
OverviewCalendarRange) – Inclusive window rows are filtered to.as_of (
date) – Date the Ley 39/2015 art. 43.2 window is evaluated against. Required and threaded from the caller, never defaulted to today.expected_tax_id (
str|None) – Taxpayer identity rows must match, when known.
- Return type:
- Returns:
A tuple of
OverviewCalendarEventmessage observations insidecalendar_range.
- calendar_events_from_justificante_capture_snapshots(snapshots, calendar_range, *, justificantes=(), expected_tax_id=None)[source]¶
Project verified live justificante captures into calendar filing events.
A
JustificanteCaptureSnapshotbecomes anOverviewCalendarEventonly after loadedJustificantemetadata proves the same CSV/model/year/period/taxpayer tuple. The event therefore carriesOverviewAeatSubmissionState.JUSTIFICANTE_VERIFIEDwithout opening a new live read.- Return type:
- Parameters:
snapshots (tuple[JustificanteCaptureSnapshot, ...])
calendar_range (OverviewCalendarRange)
justificantes (tuple[Justificante, ...])
expected_tax_id (str | None)
- build_overview_calendar_events(*, calendar_range, as_of, expedientes_snapshots=(), notification_snapshots=(), justificante_capture_snapshots=(), justificantes=(), expected_tax_id=None)[source]¶
Build observed events from persisted live-read snapshots.
The snapshots are inputs loaded by the caller. This helper only fans out through
calendar_events_from_expedientes_snapshots(),calendar_events_from_notification_snapshots(), andcalendar_events_from_justificante_capture_snapshots(), then dedupesOverviewCalendarEventrows by their stable observation keys. It performs no storage or AEAT I/O.- Parameters:
calendar_range (
OverviewCalendarRange) – Inclusive window rows are filtered to.as_of (
date) – Date the notification service-state window is evaluated against, threaded tocalendar_events_from_notification_snapshots().expedientes_snapshots (
tuple[PersistedExpedientesSnapshot,...]) – Persisted expedientes snapshots.notification_snapshots (
tuple[PersistedNotificationsSnapshot,...]) – Persisted notification snapshots.justificante_capture_snapshots (
tuple[JustificanteCaptureSnapshot,...]) – Persisted justificante captures.justificantes (
tuple[Justificante,...]) – Loaded justificante metadata for capture verification.expected_tax_id (
str|None) – Taxpayer identity rows must match, when known.
- Return type:
- actionable_post_filing_events(events)[source]¶
Return the observed
OverviewCalendarEventrows that demand operator attention.An event is actionable when its
post_filing_kindis a member ofACTIONABLE_POST_FILING_EVENT_KINDS— a requerimiento, a propuesta / acuerdo de liquidación, a procedimiento sancionador, or a recaudación enforcement act (providencia de apremio or diligencia de embargo). These are the post-filing events an operator must not miss; the overview surfaces them so a pulled requerimiento is not buried in an undifferentiated message list.An event is ALSO actionable, independent of its procedural category, when its
notificacion_estado_servicioisRECHAZO_TACITO. A plainnotificacionwhose concepto matches no sharper pattern falls outside every actionable category, so before this second limb a formal notification that lapsed into deemed service under Ley 39/2015 art. 43.2 reached the operator on no day at all — while the taxpayer already bore its consequences. The limb is deliberately narrow: only the deemed-served state qualifies, so an ordinary read receipt or an in-window notification stays non-actionable and the surface does not regress to flagging every message.The result preserves the input order (the callers pass deduped, sort-stable event tuples).
- Return type:
- Parameters:
events (tuple[OverviewCalendarEvent, ...])
- calendar_events_from_modelo_records(filing_records, calendar_range, *, justificantes=(), expected_tax_id=None)[source]¶
Project persisted Modelo filing records into calendar filing events.
A
ModeloRecordalways contributes on theOverviewLocalFilingStateaxis. It only contributesOverviewAeatSubmissionStatewhen its external evidence reference is corroborated by loadedJustificantemetadata for the same taxpayer and filing target.- Parameters:
filing_records (
tuple[ModeloRecord,...]) – The persistedModeloRecordfilings to project.calendar_range (
OverviewCalendarRange) – The window that bounds which records become events.justificantes (
tuple[Justificante,...]) – Optional AEAT justificantes corroborating the filings.expected_tax_id (
str|None) – The taxpayer NIF the justificantes must match.
- Return type:
- Returns:
A tuple of
OverviewCalendarEvent, one per in-range record.
- build_overview_calendar(profile, calendar_range, *, operation, today, engine=None, raw_values=None, show_suppressed=False, events=(), filing_evidence=(), work_units=(), live_censo_verified_profile_keys=None)[source]¶
Build a typed calendar view for
profileovercalendar_range.Composes the existing
DeadlineEngineover each year the range spans, filters obligations to those whose filing window intersects the range, attaches the user-state mapping, merges already-loadedOverviewCalendarFilingEvidence, enrichesOverviewCalendarEventrows, and returns the typedOverviewCalendar. The builder does not load repositories and does not contact AEAT.- Parameters:
profile (
TaxpayerProfile) – The operator’sTaxpayerProfile.calendar_range (
OverviewCalendarRange) – Inclusive date window to enumerate.operation (
PinnedAuthorityOperation) – Caller-owned generation-pinned authority operation used by the deadline engine, holiday projection, and warning metadata.today (
date) – Reference date for engine status classification.engine (
ScheduleProducer|None) – OptionalScheduleProducerthe caller wants to share across queries — a concreteDeadlineEngineor any object satisfying the schedule-producing protocol. WhenNone, a defaultDeadlineEngineis constructed.raw_values (
Mapping[str,object] |None) – Optional mapping of casilla id to raw value, forwarded to the engine for user-state annotation. WhenNone, the engine uses an empty mapping.show_suppressed (
bool) – WhenTrue, populateOverviewCalendar.suppressed_entrieswith the obligations filtered out by a non-APPLICABLEapplicability verdict. Default isFalse— the standard calendar view excludes suppressed rows from the payload entirely.events (
tuple[OverviewCalendarEvent,...]) – Optional observed calendar events, usually projected from persisted local live-read snapshots by the CLI.filing_evidence (
tuple[OverviewCalendarFilingEvidence,...]) – Optional local/AEAT evidence rows keyed to calendar obligations. These rows are preloaded by callers that own storage access; the calendar builder only merges them onto legal deadline entries.work_units (
tuple[WorkUnit,...]) – Optional active or audit-loaded Modelo work units. Active units are merged onto matching registry rows or projected as local-work-unit rows when registry windows do not cover the historical target.live_censo_verified_profile_keys (
tuple[str,...] |None) – Optional profile paths whose current values carry live Modelo 036 / censo provenance. When supplied, active Modelo rows whose applicability cannot be tied to any such path receive a blocking calendar warning.
- Return type:
A year inside the range with no registered deadline windows is treated as a “no data yet” state: that year contributes zero entries and the calendar still succeeds for every year that does have window data. This is the same graceful degradation
overview explainapplies to a modelo/year pair with no registered windows.- Return type:
- Returns:
A
OverviewCalendarwith one entry per(modelo, period)whose filing window intersects the range.- Parameters:
profile (TaxpayerProfile)
calendar_range (OverviewCalendarRange)
operation (PinnedAuthorityOperation)
today (date)
engine (ScheduleProducer | None)
show_suppressed (bool)
events (tuple[OverviewCalendarEvent, ...])
filing_evidence (tuple[OverviewCalendarFilingEvidence, ...])