manicanldes-backend/docs/production-material-stock-a...

1.7 KiB

Production material stock (Phase 2O)

After a production batch is completed and usage has been recorded for every production BOM line, post its consumed and wasted material to one selected warehouse. Both quantities reduce on-hand stock in each material's native unit. Packaging consumption is documented separately; finished-goods receipts are a later milestone.

Method Path Permission
GET /api/v1/production-batches/:batchId/material-stock-posting inventory.read
POST /api/v1/production-batches/:batchId/material-stock-posting inventory.manage

POST body: { "warehouseId": "<uuid>", "idempotencyKey": "<uuid>" }. The posting returns one negative ledger entry per recorded production material usage event. A batch can be posted only once. Repeating the same key and request returns the original posting; changing the warehouse with that key returns PRODUCTION_STOCK_REPLAY_CONFLICT. A new key for an already posted batch returns PRODUCTION_STOCK_ALREADY_POSTED.

The requested warehouse must contain enough of every material for the batch's total consumed plus wasted quantity. Otherwise PRODUCTION_STOCK_INSUFFICIENT is returned and neither the posting nor any ledger entry is committed. Posting, ledger entries and balance changes share one database transaction. PostgreSQL independently checks the batch state, the usage event and material/warehouse relationship, exact signed quantity, and nonnegative balance. Posting headers and ledger entries cannot be edited or deleted.