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:
BaseModelOne row in
inventory list.The row summarizes actividad, year,
ValuationMethod, opening stock, and movement count without returning the fullInventoryLedger.- Parameters:
actividad_id (str)
year (int)
valuation_method (ValuationMethod)
opening_stock (Decimal)
movement_count (int)
- actividad_id: str¶
- year: int¶
- valuation_method: ValuationMethod¶
- opening_stock: Decimal¶
- movement_count: int¶
- 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:
- 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:
BaseModelOperator-facing projection of an
InventoryValuationResult.- Parameters:
actividad_id (str)
year (int)
valuation_method (ValuationMethod)
closing_stock (Decimal)
cogs (Decimal)
- actividad_id: str¶
- year: int¶
- valuation_method: ValuationMethod¶
- closing_stock: 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:
ledger (InventoryLedger)
- ledger: InventoryLedger¶
- bucket_event_ids: tuple[str, ...]¶
- class InventoryValuationPreviewResult(**data)[source]¶
Bases:
BaseModelReturn record from
valuation_previewplus emitted event id.- Parameters:
preview (InventoryValuationPreview)
- preview: InventoryValuationPreview¶
- bucket_event_ids: tuple[str, ...]¶
- InventoryRepositoryFactory¶
Factory that builds an
InventoryLedgerRepositoryfor a bucket id.alias of
Callable[[str],InventoryLedgerRepository]
- class InventoryService(settings=None, bucket_event_repository=None, repository_factory=None)[source]¶
Bases:
objectBucket-scoped CRUD over per-actividad
InventoryLedgerrecords.Runtime construction routes the repository through
secure_object_repository_for_bucket(), so the requestedbucket_idis checked by the storage runtime instead of bypassing custody with a local file path. Tests may inject anInventoryLedgerRepositoryfactory orBucketEventHistoryRepositoryprotocol implementation.- Parameters:
settings (Settings | None)
bucket_event_repository (BucketEventHistoryRepositoryProtocol | None)
repository_factory (InventoryRepositoryFactory | None)
- 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:
- 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: