manicanldes-backend/docs/production-batches-api.md

2.5 KiB
Raw Permalink Blame History

Production batches (Phase 2H)

A batch records a planned number of finished pieces against one active BOM revision. Creation requires an active product variant and a planned quantity divisible by the BOM yield. The response includes planned material quantities scaled with exact decimal arithmetic from the immutable BOM lines. If that BOM is later superseded, the batch retains its original revision.

Method Path Permission Purpose
GET /api/v1/production-batches?status=&variantId=&limit=&offset= production.read List scoped batch metadata
GET /api/v1/production-batches/:id production.read Read batch, BOM, planned materials and events
POST /api/v1/production-batches production.manage Create a draft
POST /api/v1/production-batches/:id/start production.manage Start a draft
POST /api/v1/production-batches/:id/complete production.manage Record good and rejected output
POST /api/v1/production-batches/:id/cancel production.manage Cancel a draft or started batch

Create body: { "bomId": "<uuid>", "reference": "BATCH-001", "plannedQuantity": 20, "scheduledDate": "2026-10-01" }. The date is optional. References are unique per organization, uppercase and at most 32 characters. Planned quantity is 1–100,000 pieces.

Completion body: { "goodQuantity": 18, "rejectedQuantity": 2, "rejectionReason": "Surface defects" }. Good and rejected quantities must total the plan. A nonzero rejected quantity requires a reason. Cancellation body: { "reason": "Production halted" }.

The permitted lifecycle is DRAFT → IN_PROGRESS → COMPLETED or DRAFT/IN_PROGRESS → CANCELLED. Every transition is audited. Completion and cancellation records are immutable. Database checks and triggers enforce state transitions, event reconciliation, organization scope and unique references. A batch does not adjust finished-goods stock or consume material; those require stock-location, consumption and QC decisions in later milestones.