25 lines
2.0 KiB
Markdown
25 lines
2.0 KiB
Markdown
# Production material usage (Phase 2I)
|
||
|
||
Usage events record material consumed into a batch or wasted while it is `IN_PROGRESS`. Each event references a material line in that batch's immutable BOM revision. Events are append-only and organization scoped. They document actual usage; they do not deduct inventory or price the material.
|
||
|
||
| Method | Path | Permission | Purpose |
|
||
| ------ | ------------------------------------------------------------------- | ---------------------------- | ------------------------------------------------------- |
|
||
| GET | `/api/v1/production-batches/:batchId/material-usage?limit=&offset=` | `production.read` | Get paginated events and full plan-versus-actual totals |
|
||
| POST | `/api/v1/production-batches/:batchId/material-usage` | `production.material.record` | Record consumption or wastage |
|
||
|
||
Example record:
|
||
|
||
```json
|
||
{
|
||
"bomLineId": "<uuid>",
|
||
"kind": "WASTED",
|
||
"quantity": "0.125",
|
||
"reason": "Spill during pouring",
|
||
"idempotencyKey": "<uuid>"
|
||
}
|
||
```
|
||
|
||
`kind` is `CONSUMED` or `WASTED`. Quantity is positive with exactly three decimal places, in the BOM material's unit. Waste requires a reason. A batch accepts at most 500 usage events. Retrying the same request with the same idempotency key returns the original event, even after the batch closes; reusing the key with changed content returns `USAGE_REPLAY_CONFLICT`.
|
||
|
||
The GET response includes `total`, an `events` page and a `materials` summary for every BOM line. For each line, `varianceQuantity = plannedQuantity − consumedQuantity − wastedQuantity`; a negative number shows overuse. Totals use exact decimal arithmetic and include all events, regardless of pagination. A completed batch need not have usage records because the earlier batch lifecycle does not require them. Stock-location policy, physical stock posting, reconciliation and costing are later decisions.
|