aeat.application.modelo._revision_persistence module¶
Repository mutation helpers for modelo calculation and filing transitions.
The calculate path stores draft CalculationRevision rows with their
provenance-bearing CasillaObservation entries, advances the parent
WorkUnit pointer, and emits modelo.calculation.created through the
BucketEventHistoryRepository catalogue. The event is a lightweight join
record; full legal/source provenance remains on the persisted calculation
revision’s observations, with has_provenance signalling that the join is
grounded.
The filing path runs here only after its caller has passed readiness, workflow,
and clean-state gates. It records the local/internal filing transition: create a
current ModeloRecord, supersede any prior current filing for the work
target, move calculation revisions into PRESENTADO states, and co-emit
the TransactionRevisionParticipationIndex writes,
cross-period observation projections, and Modelo 303 settlement prorrata
register writeback. It never submits to AEAT and never turns the non-official
app_filing carry projection into filing-grade external evidence.
See also
file_modelo_revision():Orchestrates preconditions and result-disposition resolution before delegating successful mutations here.
import_external_filing_evidence():Separate import boundary that creates current records with
ExternalEvidence; this persistence helper deliberately creates local records without that payload.persist_filed_revision_observation():Projects filed casilla observations into non-official cross-period carry evidence.
ProrrataRegisterRepository:Profile-scoped encrypted repository co-emitted for Modelo 303 settlement prorrata writeback.
ProrrataRegisterEntry:Typed row updated with definitive percentage and annual volume inputs.
- emit_bucket_event(*, repository, bucket_id, event_type, occurred_at, actor, object_type, object_id, payload)[source]¶
Append one
BucketEventto the bucket-event-history catalogue.The returned event is the durable bucket-scoped audit pointer for the domain mutation. Payloads stay compact and reference the owning calculation revision, filing record, or work unit instead of duplicating their full catalogued state.
- Return type:
- Parameters:
repository (BucketEventHistoryRepositoryProtocol)
bucket_id (str)
event_type (BucketEventType)
occurred_at (datetime)
actor (str)
object_type (BucketEventObjectType)
object_id (str)
- persist_calculation_revision(*, work_unit_id, work_unit, work_units, input_values_by_casilla_id, binding_overrides, row_binding_values, relation_overrides, casilla_values, source_transaction_ids, borrador_snapshot_id, bindings_sourced_from_borrador, observations, unresolved_outcomes=(), source_provenance=(), detail_rows, formula_count, actor, now, calculation_repository, work_unit_repository, bucket_event_repository)[source]¶
Persist a freshly calculated draft revision and return the
CalculationRevision.Returns the existing duplicate when an identical revision is already persisted. The content-addressed revision id includes manual casilla inputs, binding/relation overrides, ledger source transactions, borrador provenance, detail rows, and calculated casilla values. The supplied
CasillaObservationrows carry the legal and source provenance persisted with a new calculation revision.The
source_provenancetuple carries the resolver-level source-mesh trace (CalculationSourceRefrows projected from the calculation source mesh) so the persisted revision records which resolver mesh and which upstream source objects produced it. It is additive and does NOT participate inderive_calculation_revision_id.The emitted
BucketEventuses the revision id asobject_idand includes ahas_provenancepayload flag plus asource_provenance_countand an order-independentsource_provenance_trace_sha256digest of the source-mesh trace. Audit readers can therefore use the event as a compact pointer back to the persistedCalculationRevision, and detect a source-connectivity change from the digest without decrypting the revision, instead of treating bucket history as the standalone provenance store.- Return type:
- Parameters:
work_unit_id (str)
work_unit (WorkUnit)
work_units (WorkUnitCatalogue)
borrador_snapshot_id (str | None)
bindings_sourced_from_borrador (tuple[BindingId, ...])
observations (tuple[CasillaObservation, ...])
unresolved_outcomes (tuple[RegistryCalculationUnresolvedOutcome, ...])
source_provenance (tuple[CalculationSourceRef, ...])
detail_rows (tuple[Modelo184MemberRow | Modelo232VinculadaRow | Modelo349OperadorRow | Modelo349RectificacionRow | Modelo347ContraparteRow, ...])
formula_count (int)
actor (str)
now (datetime)
calculation_repository (CalculationRevisionCatalogueRepositoryProtocol)
work_unit_repository (WorkUnitCatalogueRepositoryProtocol)
bucket_event_repository (BucketEventHistoryRepositoryProtocol)
- persist_filed_revision(*, target, work_unit, work_units, notes, actor, now, calculation_repository, filing_repository, work_unit_repository, bucket_event_repository, calculation_observation_repository=None, participation_index_repository=None, prorrata_register_repository=None, refunded=False, taxpayer_nif=None)[source]¶
Persist a verified-complete calculation revision and return a
ModeloRecord.The caller has already run verification/workflow/readiness gates. The
targetCalculationRevisionis the verified-complete source revision that becomesPRESENTADOwhen this transition succeeds. The parentWorkUnitis advanced to the new current filing record after the calculation and filing catalogues are saved.When
calculation_observation_repositoryis supplied, the filed revision’s observations are co-emitted withMODELO_FILEDthroughpersist_filed_revision_observation(), so later calculations can carry them through theprevious_filingresolver. The record is stamped with NON-officialapp_filingand never satisfies the cross-period clean-state filing gate; useimport_external_filing_evidence()when the current record must carryExternalEvidence.refundedis resolved once at the calculate/file boundary byresolve_modelo_result_disposition. For refunded Modelo 303 filings (devolución, Tipo de declaraciónD), it tellspersist_filed_revision_observation()to persist ZERO compensación carry; the defaultFalsepreserves standard carry (RD 1624/1992 art. 30 / Ley 37/1992 art. 116).For Modelo 303 settlement periods, the filed definitive prorrata percentage and annual volume inputs are also co-emitted to the profile
ProrrataRegisterthroughProrrataRegisterRepositoryin the same secure-object save as the filing catalogue and filed calculation revision.- Return type:
- Parameters:
target (CalculationRevision)
work_unit (WorkUnit)
work_units (WorkUnitCatalogue)
notes (str | None)
actor (str)
now (datetime)
calculation_repository (CalculationRevisionCatalogueRepositoryProtocol)
filing_repository (ModeloRecordCatalogueRepositoryProtocol)
work_unit_repository (WorkUnitCatalogueRepositoryProtocol)
bucket_event_repository (BucketEventHistoryRepositoryProtocol)
calculation_observation_repository (CalculationObservationRepository | None)
participation_index_repository (TransactionParticipationIndexRepository | None)
prorrata_register_repository (ProrrataRegisterRepositoryProtocol | None)
refunded (bool)
taxpayer_nif (str | None)