1.9 KiB
Batch cost snapshots (Phase 2M)
Create one immutable standard-cost snapshot after a production batch is completed. The snapshot prices recorded material consumption and wastage, plus recorded packaging use and wastage, using the latest material cost rates in one selected currency at creation time. It stores the exact rate IDs, material quantities, line costs and totals, so later rate revisions cannot change it.
| Method | Path | Permission |
|---|---|---|
| GET | /api/v1/production-batches/:batchId/cost-snapshot |
cost.read |
| POST | /api/v1/production-batches/:batchId/cost-snapshot |
cost.manage |
POST body: { "currency": "INR", "idempotencyKey": "<uuid>" }. Supported currencies are INR, USD, EUR and GBP. A batch has at most one snapshot. An exact retry with the same key returns the saved snapshot; a changed request returns BATCH_COST_REPLAY_CONFLICT.
Every production BOM line must have at least one material usage event before batch completion. A batch with good output also needs its packaging execution record. A fully rejected batch with zero good pieces can be costed without packaging. Missing usage, packaging or cost rates return distinct errors. Completed legacy batches without usage events cannot be costed retroactively because material usage is append-only and closes with the batch.
Each line adds used and wasted quantities, multiplies by its selected standard rate, and rounds half-up to two decimal places. Production and packaging totals sum their rounded lines; the overall total sums those subtotals. Quantities stay in each material's native unit. These snapshots are operational standard-cost reports, not stock valuation or accounting COGS; they exclude labor, overhead, tax and freight. Physical stock posting remains a separate milestone pending a stock-location policy.