manicanldes-backend/docs/bom-api.md

25 lines
2.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Product bills of materials (Phase 2G)
Every BOM belongs to one product variant and organization. A revision specifies the number of finished pieces it yields and the required quantity of each material for that yield. Quantities use the material's native unit and exactly three input decimal places. The API does not convert grams to kilograms or assume a wastage rate.
| Method | Path | Permission | Purpose |
| ------ | --------------------------------------------------------- | ------------ | --------------------------------------------------------- |
| GET | `/api/v1/variants/:variantId/boms?status=&limit=&offset=` | `bom.read` | List revision metadata, newest first |
| GET | `/api/v1/variants/:variantId/boms/active` | `bom.read` | Get the current active revision with lines |
| POST | `/api/v1/variants/:variantId/boms` | `bom.manage` | Create a complete draft revision |
| GET | `/api/v1/boms/:id` | `bom.read` | Get one revision with material snapshots |
| POST | `/api/v1/boms/:id/activate` | `bom.manage` | Activate a draft and supersede the former active revision |
Create body:
```json
{
"outputQuantity": 10,
"lines": [{ "materialId": "a-valid-uuid", "quantity": "125.000" }]
}
```
Use an actual UUID for `materialId`. One to 50 distinct active materials are required. The output is 1–100,000 pieces, and a variant can have at most 100 revisions. Only active variants and materials may be used. Material name, code and unit are copied into the revision and do not change when master data changes. Drafts are complete when created; corrections use another revision. Activating an older draft after a newer revision has been activated is rejected. An existing activation remains auditable even if its material master is subsequently deactivated.
All reads and writes are organization scoped. The create and activate paths write audit events. Database constraints and triggers enforce sequential revisions, positive quantities, one active revision per variant, immutable lines, and permitted lifecycle transitions. Production batches, actual consumption, wastage, packaging and costing remain later milestones; a BOM is a planned recipe, not a stock movement.