aeat.adapters.persistence.profile.inventory module

Encrypted SQL persistence for actividad economica inventory ledgers.

InventoryLedger payloads are grouped in InventoryLedgerDocument and stored as FINANCIAL adapters.persistence.storage.SensitivityClass secure objects in the primary database through adapters.persistence.storage.SecureObjectRepository. The singleton namespace, default object key, schema version, and custody contract come from adapters.persistence.storage.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.

load_inventory()[source]

Load inventory ledgers from the encrypted ledger.

Return type:

tuple[InventoryLedger, ...]

Returns:

Tuple of InventoryLedger records, empty when no envelope exists.

save_inventory(ledgers)[source]

Persist ledgers as a governed FINANCIAL-class secure object.

The storage contract comes from adapters.persistence.storage.PROFILE_INVENTORY_LEDGER_NAMESPACE.

Parameters:

ledgers (tuple[InventoryLedger, ...]) – Inventory ledgers to persist.

Return type:

Path

Returns:

Logical path identifying the secure object.

create_inventory_ledger(ledger)[source]

Atomically create ledger and refuse duplicate (actividad, year) pairs.

Parameters:

ledger (InventoryLedger) – Inventory ledger to insert.

Return type:

InventoryLedgerDocument

Returns:

The updated InventoryLedgerDocument including the newly inserted ledger.

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.PROFILE_INVENTORY_LEDGER_NAMESPACE and persisted through adapters.persistence.storage.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.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.

Raises:

InventoryLedgerError – When a ledger with the same (actividad_id, year) pair exists.

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.

Raises:

InventoryLedgerError – When the target ledger does not exist or the movement id is duplicated.