cadrumo.domain.modelos.filing_record module¶
Filing-record store paired with filed calculation revisions.
A ModeloRecord is the durable receipt of an
internal filing event: at time T, actor A marked calculation revision R of work
unit W as the current filed answer for (bucket, modelo, year, period). The
filing record holds filing-event state (filed timestamp, actor, notes,
origin, AEAT confirmation state, declaration kind, supersession and amendment
links); the filed calculation revision holds
the immutable calculation result. The two are paired so the calculation revision
never accretes filing-side concerns.
There is at most one current filing record per (bucket_id, modelo,
filing_year, period) tuple. When a later verified revision is filed,
the previous current record is superseded — its
superseded_by_filing_record_id is set, the calculation revision
it pointed at moves from FILED to FILED_SUPERSEDED, and the
new filing record becomes current. Both records remain in the
catalogue for audit.
The records of one tuple form a linear chain. A local filing is only an
intention (PENDIENTE) until an AEAT register entry proves it was presented
(CONFIRMADA); only confirmed records carry ExternalEvidence, and
the filing record itself never initiates a live submission.
- class ModeloRecordStatus(*values)[source]¶
Bases:
StrEnumClosed enumeration of filing-record lifecycle states.
VIGENTE— the record is the currently-effective filed answer for its (bucket, modelo, year, period) tuple.SUPERSEDIDO— a later filing replaced this one. The record remains for audit;superseded_by_filing_record_idpoints at the successor.
- VIGENTE¶
- SUPERSEDIDO¶
- class ExternalEvidenceKind(*values)[source]¶
Bases:
StrEnumClosed catalogue of external-evidence kinds.
A
ModeloRecordmarked with one of these kinds carries imported official evidence (justificante, CSV register, or live capture) rather than a tool-computed calculation revision. This is the gateamend_modelo_revision()requires before it accepts an amendment baseline.- AEAT_JUSTIFICANTE_PDF¶
- AEAT_CSV_REGISTER¶
- AEAT_LIVE_CAPTURE¶
- is_justificante_backed_external_evidence(kind)[source]¶
Return whether
kindrequires matching persisted receipt metadata.Every current external-evidence kind is filing-grade only after its reference resolves to a matching
domain.justificante.schema.Justificante. Keeping this closed policy beside the enum prevents application consumers from silently disagreeing when a new evidence kind is introduced.- Return type:
- Parameters:
kind (ExternalEvidenceKind)
- is_receipt_bound_external_evidence(kind)[source]¶
Return whether
kindrequires persisted Justificante metadata.- Return type:
- Parameters:
kind (ExternalEvidenceKind)
- class ExternalEvidence(**data)[source]¶
Bases:
BaseModelImported-evidence metadata for an externally-filed return.
Populated by
import_external_filing_evidence()for a currentModeloRecord; consumed byamend_modelo_revision()as the gate that proves the baseline is AEAT-attested and not a fabricated local draft.- Parameters:
data (Any)
- kind: ExternalEvidenceKind¶
- reference_id: EvidenceReference¶
- imported_at: UtcInstant¶
- class FilingOrigin(*values)[source]¶
Bases:
StrEnumWho authored a chain entry: this application, or AEAT’s own register.
- LOCAL¶
- AEAT¶
- class AeatConfirmationState(*values)[source]¶
Bases:
StrEnumWhether AEAT has been seen to hold a chain entry.
PENDIENTE– filed locally, not yet observed at AEAT.CONFIRMADA– backed by an AEAT register entry and its evidence.DISCREPANTE– AEAT holds different content for the presentation; the entry is superseded by the AEAT entry.DESCARTADA– a pending entry replaced before it was ever presented.
- PENDIENTE¶
- CONFIRMADA¶
- DISCREPANTE¶
- DESCARTADA¶
- class FilingDeclarationKind(*values)[source]¶
Bases:
StrEnumLegal kind of a declaration in a period’s chain.
- ORIGINAL¶
- COMPLEMENTARIA¶
- SUSTITUTIVA¶
- RECTIFICATIVA¶
- declaration_kind_for_tipo_solicitud(tipo_solicitud)[source]¶
Return the correction kind an AEAT register
tipo_solicitudnames, orNone.Only a value naming exactly one correction kind is read; any other value, including one describing an original declaration, stays
Noneso the caller never assumes a kind AEAT did not state.- Return type:
- Parameters:
tipo_solicitud (str | None)
- class AeatRegisterRef(**data)[source]¶
Bases:
BaseModelAEAT’s own identifiers for one presented declaration.
The register expediente and the receipt identifiers (CSV and número de justificante) are different AEAT namespaces; each is
Nonewhen the source did not state it, and at least the expediente or the CSV is present.presented_atis optional because a printed justificante states a Europe/Madrid wall-clock time without an offset, and no instant may be invented from it.- Parameters:
data (Any)
- expediente_id: EvidenceReference | None¶
- csv: AeatCsv | None¶
- justificante_number: AeatPresentationId | None¶
- tipo_solicitud: _TipoSolicitud | None¶
- presented_at: UtcInstant | None¶
- derive_filing_record_id(*, work_unit_id, calculation_revision_id, filed_by, member_nif=None)[source]¶
Deterministic 64-char SHA-256 id for a filing record.
Content-addressed by the filing outcome - the parent work unit, the filed calculation revision, the actor, and (for member-scoped group filings) the member NIF.
filed_atis deliberately excluded from the identity so a re-file of the same revision by the same actor resolves to the same record (an idempotent re-file is a no-op, not a new time-stamped duplicate);filed_atis retained onModeloRecordas a non-identity last-seen field. Member-scoped group filings include the member NIF in the identity; single-filer records omit it.
- class ModeloRecord(**data)[source]¶
Bases:
BaseModelDurable receipt of one internal filing event for an AEAT modelo (tax form).
Pairs a filed
CalculationRevisionIdwith the filing event metadata (actor, timestamp, notes, origin, confirmation state, declaration kind, supersession and amendment links). The id is content-addressed by the filing outcome -work_unit_id,calculation_revision_id,filed_by, and (for member-scoped group filings)member_nif- viaderive_filing_record_id();filed_atis a non-identity last-seen field, so a re-file of the same revision by the same actor is an idempotent no-op rather than a new record. Amodel_validatorenforces the derivation on construction.confirmationrecords externally-observed AEAT acceptance; it does not imply that the application submitted anything.CONFIRMADAtravels withExternalEvidenceand no other state carries it. AnAEAT-origin record is alwaysCONFIRMADA; the retired states (DISCREPANTE,DESCARTADA) are local entries that are no longer in force.- Parameters:
data (Any)
- filing_record_id: FilingRecordId¶
- work_unit_id: WorkUnitId¶
- calculation_revision_id: CalculationRevisionId¶
- bucket_id: BucketId¶
- modelo: ModeloCode¶
- filing_year: FilingYear¶
- period: Period¶
- member_nif: _MemberNif | None¶
- filed_at: UtcInstant¶
- filed_by: ModeloActorLabel¶
- notes: FilingNotes | None¶
- origin: FilingOrigin¶
- confirmation: AeatConfirmationState¶
- declaration_kind: FilingDeclarationKind¶
- aeat_register: AeatRegisterRef | None¶
- status: ModeloRecordStatus¶
- superseded_at: UtcInstant | None¶
- superseded_by_filing_record_id: FilingRecordId | None¶
- external_evidence: ExternalEvidence | None¶
- amends_filing_record_id: FilingRecordId | None¶
- source_transaction_ids: tuple[TransactionId, ...]¶
- class ModeloRecordCatalogue(**data)[source]¶
Bases:
BaseModelImmutable catalogue of every filing record in a bucket’s storage.
Keyed by
filing_record_id; the model validator enforces that every key equals the id of theModeloRecordit maps to, and that at most one record per (bucket_id, modelo, filing_year, period, member_nif) tuple carriesstatus=VIGENTE. Iteration yieldsModeloRecordvalues (not key–value pairs) — the override is annotated with a suppression comment on__iter__.- Parameters:
data (Any)
- records: Mapping[str, ModeloRecord]¶
- get(filing_record_id)[source]¶
Return the
ModeloRecordforfiling_record_id, orNone.- Return type:
- Parameters:
filing_record_id (str)
- current_for(*, bucket_id, modelo, filing_year, period, member_nif=None)[source]¶
Return the current (non-superseded)
ModeloRecordfor a filing tuple.Returns
Nonewhen no filing has ever happened for the tuple.member_nif=Nonemeans the single-filer or aggregate record, not every member. Returns the active filing record when one exists. Never returns a superseded record — callers must iteraterecordsdirectly to walk audit history.
- latest_confirmed_for(*, bucket_id, modelo, filing_year, period, member_nif=None)[source]¶
Return the most recent AEAT-confirmed record for a filing tuple.
This is the declaration a correction must reference. It differs from
current_for()while a local entry is pending.
- history_for(*, bucket_id, modelo, filing_year, period, member_nif=None)[source]¶
Return every filing record for a tuple, ordered by filed_at.
- Return type:
- Returns:
Tuple of
ModeloRecordobjects ordered by filing timestamp.- Parameters:
- values()[source]¶
Return a view of all
ModeloRecordvalues in the catalogue.