W137: Create receipt against work order
Records production output from a work order. Triggered from Work Order Detail receipts section. The WO equivalent of the PO receipt: consumes inputs from both ledgers using the recipe snapshot and produces finished goods into the FG ledger, all in one transaction.
Steps
-
Confirm the WO and capture context. Call
WorkOrders.getWoById; reject if the WO isCancelled. CapturewoNumberandworkSiteLocationId. -
Create the receipt header. Call
WorkOrders.createReceiptwithreceiptDateandnotes. -
Post each output line, its input consumption, and its production entry. For every received output line: call
WorkOrders.addReceiptItem. Load the line's recipe snapshot viaWorkOrders.listInputsByItem(woItemId). For each snapshot row:- Material input: write
MaterialsInventory.recordConsumptionwithquantity = snapshot.quantity × receivedQuantity / wo_item.quantity,locationId = workSiteLocationId,ref = woNumber,unitCost= FIFO weighted-average for that material at the work-site location at consume time (oldest layers consumed first). - SKU sub-assembly input: write
FinishedGoodsInventory.recordConsumptionwith the equivalent shape,unitCost= FIFO weighted-average for the input SKU at the work-site location at consume time. Then writeFinishedGoodsInventory.recordProduction(event typePRODUCE) for the output SKU withquantity = receivedQuantity,locationId = workSiteLocationId,ref = woNumber,unitCost = wo_item.materialUnitCost + wo_item.conversionCost(the snapshot's current cost values).
- Material input: write
-
Advance the WO status. If cumulative received per line meets or exceeds expected, transition to
Received; otherwise transition toPartial. CallWorkOrders.updateWo.
Returns
The new receipt with its received-item rows.
Business rules
- Atomic. Steps 2 through 4 share a single transaction; consumption, production, and status advance commit together.
- Consumption is computed from the snapshot. BOM edits after WO creation are invisible to receipts; the recipe (identity and quantity) is frozen on the WO. Cost values on the snapshot may have been updated by W027's cascade since creation; whatever they are at consume time is what gets stamped.
- Over-production is allowed. Receipts may exceed expected quantity; the WO simply lands in
Received. - Consume costing is a v1 gap. Per the spec, CONSUME
unitCostshould be the FIFO weighted-average at consume time and PRODUCEunitCostshould includematerialUnitCost; v1 stamps0on CONSUME andconversionCostonly on PRODUCE, pending the cost-cascade work. - No stock guard in v1. Consumption draws from the work-site location's on-hand without blocking on insufficient stock; the materials and FG ledgers can go negative on under-stock. Stock protection is a future concern.
- Receipt-driven transition. The
Partial/Receivedtransition in step 4 bypasses the manual map; it is computed from the ledger.
Errors
NotFoundError. The WO was not found.InvalidTransitionError. The WO isCancelled.ValidationError. A receipt line references awoItemIdthat doesn't belong to this WO.