aeat.application.overview._calendar_evidence module

Calendar event dedup and filing-evidence reconciliation for the overview read model.

Extracted from _calendar (size-budget split) to keep the calendar module and its build_overview_calendar entry point under their line-count overrides. This module owns two cohesive concerns:

  • Deterministic dedup of observed OverviewCalendarEvent rows across multiple local snapshots (_calendar_event_sort_key, _dedupe_calendar_events), shared by every calendar-events builder.

  • Reconciling already-loaded local and AEAT-side signals – filed Modelo records, observed register events, filed-declaration observations, persisted calculation observations, live justificante captures, and loaded justificante metadata – into typed OverviewCalendarFilingEvidence rows (calendar_filing_evidence_from_sources()), and merging that evidence back onto calendar entries and events.

This module is local-only and pure with respect to I/O, exactly like its parent: it never starts a live AEAT read and never verifies a justificante by fetching external state; it only reconciles evidence the caller has already loaded.

calendar_filing_evidence_from_sources(*, filing_records=(), observed_events=(), filed_declaration_observations=(), verified_filed_declaration_artefact_refs=(), verified_filed_declaration_artefact_csvs=None, calculation_observations=(), justificante_capture_snapshots=(), justificantes=(), expected_tax_id=None)[source]

Build OverviewCalendarFilingEvidence from local records and observed AEAT signals.

The function is pure and intentionally accepts already-loaded records. CLI/storage code owns I/O; this projection only reconciles the existing local ModeloRecord catalogue, calendar-visible AEAT register events, FiledDeclaracionObservation rows, persisted calculation observations from justificante capture, JustificanteCaptureSnapshot rows, and already-loaded justificante metadata. The filing_records are filed ModeloRecord rows whose external justificante references are only promoted to justificante_verified when matching persisted metadata exists for the same CSV/model/year/period/taxpayer. Filed-declaration observations are only promoted to justificante_verified when their justificante artefact storage reference is listed in verified_filed_declaration_artefact_refs by the storage layer that loaded and hashed the encrypted artefact body.

The result keeps OverviewLocalFilingState and OverviewAeatSubmissionState independent so imported AEAT baselines, local filings, observed submissions, and verified justificantes do not overwrite each other’s meaning.

Return type:

tuple[OverviewCalendarFilingEvidence, ...]

Parameters: