W087: Create BOM
Creates the recipe linking input materials and input SKUs to an output SKU. Triggered from the BOM page or from BOM Detail for a SKU that doesn't yet have a recipe. The header and items are inserted atomically.
Steps
-
Validate the output SKU. Confirm it exists, is active, and does not already have a BOM (
BOM.getBomForSkumust return null). -
Validate input rows. For each input row, confirm the referenced material or input SKU exists and is active. Enforce the
materialId XOR inputSkuIdinvariant per row (exactly one of the two must be set). -
Create the BOM header. Call
BOM.createBom({ outputSkuId }). -
Insert the composition atomically. Call
BOM.replaceBomItems(bomId, items).
Returns
The BOM header plus its items.
Business rules
- One BOM per output SKU. A second BOM for the same output SKU is rejected.
- Multi-level BOMs are allowed. An input SKU may itself have a BOM; the cost rollup at WO creation handles recursion via weighted averages.
- No cycle detection in v1. A pathological chain like SKU A to SKU B to SKU A is not prevented by the workflow today. Cycle detection is a future concern; for v1 the team relies on data hygiene.
Errors
NotFoundError. The output SKU, an input material, or an input SKU was missing.ValidationError. A BOM already exists for this SKU, or an input row violates the XOR invariant.