cadrumo.adapters.persistence.profile.inventory module¶
Encrypted SQL persistence for actividad economica inventory ledgers.
InventoryLedger payloads are grouped in
InventoryLedgerDocument and stored as
FINANCIAL SensitivityClass
secure objects in the primary database through
adapters.persistence.storage.sql.secure_objects.SecureObjectRepository. The
singleton namespace, default object key, schema version, and custody contract
come from
adapters.persistence.storage.secure_object_namespaces.PROFILE_INVENTORY_LEDGER_NAMESPACE.
See also
domain.contribuyente.inventoryTyped inventory ledger, movement, and valuation payload models persisted here.
application.inventoryApplication service layer that validates inventory commands before this adapter writes the encrypted secure object.
- record_movement(actividad_id, movement, *, year)[source]¶
Append
movementto an existing activity-and-year inventory ledger.- Parameters:
actividad_id (
str) – Identifier of the actividad economica owning the ledger.movement (
MovementRecord) – Movement record to append.year (
int) – Tax year of the target ledger.
- Return type:
- Returns:
The updated
InventoryLedger.
- class InventoryLedgerRepository(*, objects=None)[source]¶
Bases:
objectGoverned repository for the encrypted
InventoryLedgerDocumentsingleton.The singleton row is owned by
adapters.persistence.storage.secure_object_namespaces.PROFILE_INVENTORY_LEDGER_NAMESPACEand persisted throughadapters.persistence.storage.sql.secure_objects.SecureObjectRepository.- Parameters:
objects (SecureObjectRepository | None)
- load()[source]¶
Load the ledger, returning an empty document when absent.
- Return type:
- Returns:
Decrypted
InventoryLedgerDocument.- Raises:
InventoryLedgerError – When the envelope exists but cannot be loaded or decrypted.
- save(document)[source]¶
Persist
documentas FINANCIAL-class ciphertext.The classification, schema version, namespace, and object key are taken from
adapters.persistence.storage.secure_object_namespaces.PROFILE_INVENTORY_LEDGER_NAMESPACE.- Parameters:
document (
InventoryLedgerDocument) – Ledger document to encrypt and write.- Return type:
- create(ledger)[source]¶
Atomically create
ledgerand refuse duplicate actividad/year pairs.- Parameters:
ledger (
InventoryLedger) – Inventory ledger to insert.- Return type:
- Returns:
The
InventoryLedgerDocumentincluding the new ledger.
The document is a singleton row, so creating one ledger rewrites the whole document. Read, duplicate-check, rebuild, and write ran unguarded, so two callers creating ledgers for DIFFERENT activity/year pairs both read the same document and the later write silently discarded the earlier ledger – a lost update the pair check could never notice, because the two ledgers never met in one document.
The mutation now runs through the shared revision-guarded unit of work, with the duplicate check inside it so it is re-evaluated against the newly-current document on every attempt.
- Raises:
InventoryLedgerError – When a ledger with the same
(actividad_id, year)pair exists.SecureObjectRevisionConflictError – When contention persists across every attempt.
- Parameters:
ledger (InventoryLedger)
- Return type:
- remove(actividad_id, *, year)[source]¶
Atomically drop the ledger for
actividad_idandyear.- Parameters:
- Return type:
- Returns:
The
InventoryLedgerthat was removed.
The document is a singleton row, so removing one ledger rewrites the whole document – which means an unguarded removal discards a ledger created for a DIFFERENT activity in the interim, losing an entire activity’s inventory for an operator who was deleting something else.
The absence check runs inside the guarded unit of work, so a retry re-judges it against the newly-current document: a ledger removed by a concurrent caller must refuse as absent rather than report a second successful removal of something already gone.
- Raises:
InventoryLedgerError – When no ledger exists for the pair.
SecureObjectRevisionConflictError – When contention persists across every attempt.
- Parameters:
- Return type:
- record_movement(actividad_id, movement, *, year)[source]¶
Atomically append
movementto the target activity-and-year ledger.The domain valuation guard (rejecting movements that would produce an invalid valuation) is owned by the application inventory service, which runs it before invoking persistence; this adapter performs the storage append only and runs no domain calculation.
- Parameters:
actividad_id (
str) – Identifier of the owning actividad economica.movement (
MovementRecord) – Movement record to append.year (
int) – Tax year of the target ledger.
- Return type:
- Returns:
The updated
InventoryLedger.
Carries the same revision guard as
create(), and needs it more: appending a movement rewrites the WHOLE singleton document, so an unguarded append discarded any ledger — or any other activity’s movement — that landed between this call’s read and its write.- Raises:
InventoryLedgerError – When the target ledger does not exist or the movement id is duplicated.
SecureObjectRevisionConflictError – When contention persists across every attempt.
- Parameters:
actividad_id (str)
movement (MovementRecord)
year (int)
- Return type:
- record_closing_authority(actividad_id, authority_record, *, year)[source]¶
Atomically replace the target ledger’s complete closing-authority record.
- Return type:
- Parameters:
actividad_id (str)
authority_record (InventoryClosingAuthorityRecord)
year (int)