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.inventory

Typed inventory ledger, movement, and valuation payload models persisted here.

application.inventory

Application service layer that validates inventory commands before this adapter writes the encrypted secure object.

record_movement(actividad_id, movement, *, year)[source]

Append movement to 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:

InventoryLedger

Returns:

The updated InventoryLedger.

class InventoryLedgerRepository(*, objects=None)[source]

Bases: object

Governed repository for the encrypted InventoryLedgerDocument singleton.

The singleton row is owned by adapters.persistence.storage.secure_object_namespaces.PROFILE_INVENTORY_LEDGER_NAMESPACE and persisted through adapters.persistence.storage.sql.secure_objects.SecureObjectRepository.

Parameters:

objects (SecureObjectRepository | None)

property envelope_path: Path

Logical path retained for callers that display the storage target.

property lock_target: Path

Logical lock marker; SQL transactions govern writes.

load()[source]

Load the ledger, returning an empty document when absent.

Return type:

InventoryLedgerDocument

Returns:

Decrypted InventoryLedgerDocument.

Raises:

InventoryLedgerError – When the envelope exists but cannot be loaded or decrypted.

save(document)[source]

Persist document as 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:

None

create(ledger)[source]

Atomically create ledger and refuse duplicate actividad/year pairs.

Parameters:

ledger (InventoryLedger) – Inventory ledger to insert.

Return type:

InventoryLedgerDocument

Returns:

The InventoryLedgerDocument including 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:
Parameters:

ledger (InventoryLedger)

Return type:

InventoryLedgerDocument

remove(actividad_id, *, year)[source]

Atomically drop the ledger for actividad_id and year.

Parameters:
  • actividad_id (str) – Activity whose ledger is removed.

  • year (int) – Filing year of the ledger to remove.

Return type:

InventoryLedger

Returns:

The InventoryLedger that 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:
Parameters:
  • actividad_id (str)

  • year (int)

Return type:

InventoryLedger

record_movement(actividad_id, movement, *, year)[source]

Atomically append movement to 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:

InventoryLedger

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:
Parameters:
Return type:

InventoryLedger

record_closing_authority(actividad_id, authority_record, *, year)[source]

Atomically replace the target ledger’s complete closing-authority record.

Return type:

InventoryLedger

Parameters: