aeat.application.inventory._service module

Inventory application service: bucket-scoped CRUD over InventoryLedger.

The service persists InventoryLedgerDocument through InventoryLedgerRepository, whose runtime default is built by secure_object_repository_for_bucket(). It does not read or write plaintext inventory JSON side stores.

State-changing and audit-significant verbs append events to the per-bucket audit trail via BucketEventHistoryRepository; valuation math remains delegated to compute_inventory_valuation().

class InventoryActividadSummary(**data)[source]

Bases: BaseModel

One row in inventory list.

The row summarizes actividad, year, ValuationMethod, opening stock, and movement count without returning the full InventoryLedger.

Parameters:
actividad_id: str
year: int
valuation_method: ValuationMethod
opening_stock: Decimal
movement_count: int
class InventoryMovementCommand(**data)[source]

Bases: BaseModel

Strict input shape for inventory movement add.

The command is projected into a domain MovementRecord with a closed MovementKind before valuation and persistence.

Parameters:
movement_id: str
movement_date: date
kind: MovementKind
quantity: Decimal
unit_cost: Decimal | None
taxable_base: Decimal | None
iva_rate: Decimal
class InventoryValuationPreview(**data)[source]

Bases: BaseModel

Operator-facing projection of an InventoryValuationResult.

Parameters:
actividad_id: str
year: int
valuation_method: ValuationMethod
closing_stock: Decimal
cogs: Decimal
class InventoryLedgerResult(**data)[source]

Bases: BaseModel

Return record from a mutating inventory verb.

ledger is the affected InventoryLedger; bucket_event_ids lists the audit events emitted for the application operation.

Parameters:
ledger: InventoryLedger
bucket_event_ids: tuple[str, ...]
class InventoryValuationPreviewResult(**data)[source]

Bases: BaseModel

Return record from valuation_preview plus emitted event id.

Parameters:
preview: InventoryValuationPreview
bucket_event_ids: tuple[str, ...]
InventoryRepositoryFactory

Factory that builds an InventoryLedgerRepository for a bucket id.

alias of Callable[[str], InventoryLedgerRepository]

class InventoryService(settings=None, bucket_event_repository=None, repository_factory=None)[source]

Bases: object

Bucket-scoped CRUD over per-actividad InventoryLedger records.

Runtime construction routes the repository through secure_object_repository_for_bucket(), so the requested bucket_id is checked by the storage runtime instead of bypassing custody with a local file path. Tests may inject an InventoryLedgerRepository factory or BucketEventHistoryRepository protocol implementation.

Parameters:
create(*, bucket_id, actividad_id, year, valuation_method, opening_stock=Decimal('0'), actor='cli')[source]

Create a fresh ledger for one actividad/year. Rejects duplicates.

Saves the containing InventoryLedgerDocument, emits a LEDGER_INVENTORY_CREATED bucket event, and returns an InventoryLedgerResult.

Return type:

InventoryLedgerResult

Parameters:
list_all(*, bucket_id)[source]

Return one InventoryActividadSummary per stored ledger.

This is a read-only projection over the bucket’s InventoryLedgerDocument; it emits no bucket event.

Return type:

tuple[InventoryActividadSummary, ...]

Parameters:

bucket_id (str)

show(*, bucket_id, actividad_id, year)[source]

Return the exact InventoryLedger for actividad_id and year.

Raises InventoryActividadNotFoundError when the bucket’s inventory document has no matching actividad/year ledger.

Return type:

InventoryLedger

Parameters:
  • bucket_id (str)

  • actividad_id (str)

  • year (int)

movement_add(*, bucket_id, actividad_id, year, movement, actor='cli')[source]

Append a movement to the named ledger; refuses duplicate movement_id.

The InventoryMovementCommand is converted to a MovementRecord, then the domain valuation guard runs before persistence. Returns an InventoryLedgerResult with the updated ledger after the movement is appended.

Return type:

InventoryLedgerResult

Parameters:
valuation_preview(*, bucket_id, actividad_id, year, actor='cli')[source]

Run the domain-layer valuation engine and report closing stock + COGS.

Returns:

The valuation preview result.

Return type:

InventoryValuationPreviewResult

Parameters:
remove(*, bucket_id, actividad_id, year, actor='cli')[source]

Drop the entire ledger for actividad/year.

Raises InventoryActividadNotFoundError on absence. Otherwise saves the remaining InventoryLedgerDocument, emits LEDGER_INVENTORY_REMOVED, and returns the removed InventoryLedger in an InventoryLedgerResult.

Return type:

InventoryLedgerResult

Parameters: