aeat.adapters.persistence.profile.modelos_calculation module¶
Encrypted SQL repository for the calculation-revision catalogue.
CalculationRevisionCatalogueRepository persists and loads
CalculationRevision records in a
CalculationRevisionCatalogue via
SecureObjectRepository at
FINANCIAL SensitivityClass.
Each catalogue is wrapped in
Envelope before being written to
the encrypted BLOB per profile bucket.
This concrete repository is the persistence adapter behind the read-side
CalculationRevisionCatalogueRepositoryProtocol. It
lives in the persistence adapter (not in modelos) because its
secure-object coupling is SQL/crypto-bound; the domain package owns only the
typed CalculationRevisionCatalogue model, the pure
upsert_calculation_revision() mutator, and the
CalculationRevisionPersistenceError boundary error.
The namespace/version constants are redeclared here as the persisted-envelope
contract; the strings are preserved to avoid orphaning persisted envelopes.
See also
_modelo_runtimeBucket-id resolution and runtime secure-object factory shared by modelo persistence adapters.
CalculationRevisionCatalogueDomain catalogue payload encrypted by this repository.
CalculationRevisionCatalogueRepositoryProtocolDomain port this concrete persistence adapter implements.
MODELO_CALCULATION_REVISION_CATALOGUE_NAMESPACECentral namespace, sensitivity, schema-version, and singleton-key contract for these secure objects.
SecureObjectRepositoryRuntime-created encrypted storage boundary used for load/save.
- class CalculationRevisionCatalogueRepository(*, bucket_id=None, objects=None)[source]¶
Bases:
objectRepository over encrypted SQL-backed calculation-revision catalogue storage.
MODELO_CALCULATION_REVISION_CATALOGUE_NAMESPACEis the central namespace, schema-version, sensitivity, and singleton-key contract for the encryptedCalculationRevisionCataloguerow. The catalogue payload is wrapped inEnvelopebeforeSecureObjectRepositorypersists it, and the same envelope can be returned as aSecureObjectWritefor atomic co-writes. The class exposes the concrete load/save implementation behindCalculationRevisionCatalogueRepositoryProtocol.- Parameters:
bucket_id (str | None)
objects (SecureObjectRepository | None)
- property bucket_id: str | None¶
Identifier of the per-profile storage bucket this repository reads and writes.
A modelo (an AEAT tax form or declaration) carries calculation revisions per filing profile, and each profile owns its own encrypted bucket. This property exposes the resolved bucket identifier, or
Nonewhen the repository was constructed against a caller-suppliedSecureObjectRepositoryrather than a resolved bucket.- Returns:
The trimmed bucket identifier, or
Nonewhen no bucket was resolved.
- exists()[source]¶
Report whether a calculation-revision catalogue has been persisted.
Checks the encrypted store for an object under this repository’s namespace and key without decrypting or validating it, so a
Trueresult attests to presence only, not integrity.- Return type:
- Returns:
Truewhen a stored catalogue object exists,Falseotherwise.
- load()[source]¶
Load and decrypt the persisted calculation-revision catalogue.
A calculation revision is a dated, computed version of a modelo’s casilla values (a casilla is a numbered box on an AEAT form); the catalogue is the keyed collection of those revisions. The stored record is decrypted, its
Envelopeparsed, and its sensitivity classification and schema version checked before the payload is returned. When nothing has been persisted yet, an emptyCalculationRevisionCatalogueis returned rather than raising.- Return type:
- Returns:
The persisted
CalculationRevisionCatalogue, or an empty one when no record exists.- Raises:
CalculationRevisionPersistenceError – If the stored record fails the FINANCIAL classification check, or its envelope schema version exceeds the version this consumer supports, or an integrity error surfaces while decrypting and decoding the record.
- save(catalogue)[source]¶
Persist the calculation-revision catalogue to encrypted storage.
Wraps the catalogue (the keyed collection of a modelo’s dated calculation revisions) in an
Envelopestamped with the current schema version, write time, andFINANCIALsensitivity classification, then writes the serialised envelope to the encrypted store under this repository’s namespace and key. An existing catalogue object at that location is overwritten.- Parameters:
catalogue (
CalculationRevisionCatalogue) – TheCalculationRevisionCatalogueto serialise and store.- Return type:
- to_secure_object_write(catalogue)[source]¶
Return the secure-object upsert for
cataloguewithout committing it.The returned
SecureObjectWritecarries the sameEnvelopeandSensitivityClassclassification thatsave()would persist directly. It can be co-emitted with related secure objects (e.g. the participation index) in onesave_with_secure_object_writes()unit of work.- Return type:
- Parameters:
catalogue (CalculationRevisionCatalogue)
- save_with_secure_object_writes(catalogue, extra_writes)[source]¶
Persist
catalogueplus related secure objects in one unit of work.The catalogue save and every extra write land or fail together in a single SQL transaction, so the participation index co-emitted here can never drift from the calculation revision it indexes (per the composition-service single-writer discipline).
- Parameters:
catalogue (
CalculationRevisionCatalogue) – TheCalculationRevisionCatalogueto persist.extra_writes (
tuple[SecureObjectWrite,...]) – AdditionalSecureObjectWriteobjects to commit atomically with the catalogue.
- Return type: