cadrumo.application.inventory.service module¶
Inventory application service: bucket-scoped CRUD over InventoryLedger.
The service persists InventoryLedgerDocument and emits events through
the required InventoryServicePorts capability bundle. It does not
resolve storage routes or read and write plaintext inventory JSON side stores.
Valuation math remains delegated to compute_inventory_valuation().
- class InventoryActividadSummary(**data)[source]¶
Bases:
BaseModelOne row in
inventory list.The row summarizes actividad, year,
ValuationMethod, opening stock, and movement count without returning the fullInventoryLedger.- Parameters:
data (Any)
- actividad_id: str¶
- year: int¶
- valuation_method: ValuationMethod¶
- opening_stock: Decimal¶
- movement_count: NonNegativeInt¶
- class InventoryMovementCommand(**data)[source]¶
Bases:
BaseModelStrict input shape for
inventory movement add.The command is projected into a domain
MovementRecordwith a closedMovementKindbefore valuation and persistence.- Parameters:
data (Any)
- movement_id: str¶
- movement_date: date¶
- kind: MovementKind¶
- quantity: Decimal¶
- unit_cost: Decimal | None¶
- taxable_base: Decimal | None¶
- acquisition_cost: InventoryAcquisitionCost | None¶
- class InventoryValuationPreview(**data)[source]¶
Bases:
BaseModelOperator-facing projection of an
InventoryValuationResult.- Parameters:
data (Any)
- actividad_id: str¶
- year: int¶
- valuation_method: ValuationMethod¶
- derived_closing_value: Decimal¶
- cogs: Decimal¶
- class InventoryLedgerResult(**data)[source]¶
Bases:
BaseModelReturn record from a mutating inventory verb.
ledgeris the affectedInventoryLedger;bucket_event_idslists the audit events emitted for the application operation.- Parameters:
data (Any)
- ledger: InventoryLedger¶
- bucket_event_ids: tuple[str, ...]¶
- class InventoryValuationPreviewResult(**data)[source]¶
Bases:
BaseModelReturn record from
valuation_previewplus emitted event id.- Parameters:
data (Any)
- preview: InventoryValuationPreview¶
- bucket_event_ids: tuple[str, ...]¶
- class InventoryService(*, ports)[source]¶
Bases:
objectBucket-scoped CRUD over per-actividad
InventoryLedgerrecords.The executable composition root supplies the repository factory and event repository through
InventoryServicePorts; the service never resolves a storage route or names an adapter implementation.- Parameters:
ports (InventoryServicePorts)
- 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 aLEDGER_INVENTORY_CREATEDbucket event, and returns anInventoryLedgerResult.
- list_all(*, bucket_id)[source]¶
Return one
InventoryActividadSummaryper stored ledger.This is a read-only projection over the bucket’s
InventoryLedgerDocument; it emits no bucket event.- Return type:
- Parameters:
bucket_id (str)
- show(*, bucket_id, actividad_id, year)[source]¶
Return the exact
InventoryLedgerforactividad_idandyear.Raises
InventoryActividadNotFoundErrorwhen the bucket’s inventory document has no matching actividad/year ledger.- Return type:
- Parameters:
- movement_add(*, bucket_id, actividad_id, year, movement, actor='cli')[source]¶
Append a movement to the named ledger; refuses duplicate movement_id.
The
InventoryMovementCommandis converted to aMovementRecord, then the domain valuation guard runs before persistence. Returns anInventoryLedgerResultwith the updated ledger after the movement is appended.- Return type:
- Parameters:
bucket_id (str)
actividad_id (str)
year (int)
movement (InventoryMovementCommand)
actor (str)
- 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:
- Parameters:
- closing_authority_record(*, bucket_id, actividad_id, year, authority_record)[source]¶
Atomically validate and persist one complete closing-authority bundle.
- Return type:
- Parameters:
bucket_id (str)
actividad_id (str)
year (int)
authority_record (InventoryClosingAuthorityRecord)
- remove(*, bucket_id, actividad_id, year, actor='cli')[source]¶
Drop the entire ledger for actividad/year.
Raises
InventoryActividadNotFoundErroron absence. Otherwise saves the remainingInventoryLedgerDocument, emitsLEDGER_INVENTORY_REMOVED, and returns the removedInventoryLedgerin anInventoryLedgerResult.- Return type:
- Parameters: