W132: Update work order
Edits a WO's header fields, including status and lifecycle timestamps. Triggered from Work Order Detail. The WO status flow is Draft → Entered → Placed → Production → In Transit → Partial → Received → Completed, with Cancelled available at any point. Status is patched directly; a validated transition map is a v1 gap. Status changes drive the inventory ledgers via the reconciliation projector (step 3). Partial / Received are normally computed by the receipt workflow (W137).
Steps
-
Load the WO. Call
WorkOrders.getWoByIdto confirm existence. -
Apply the header patch. Call
WorkOrders.updateWowith the patch. Patchable fields:status,orderDate,expectedDeliveryDate,productionStartedAt,receivedAt,cancelledAt,notes. -
Reconcile the inventory ledger to the new status. Run the status → ledger reconciliation projector. It ensures the net-active set for the current status: FG
ORDERper output line andDEMANDper BOM-snapshot input once status leavesDraft;ALLOCATEper input fromProductiononwards (In Transit,Partial,Received,Completed). A backward transition that drops an event, orCancelled(which reverses everything), emits the matchingREVERSE_*entry. The projector is idempotent — a patch that doesn't change the desired set writes nothing.CONSUME/PRODUCEstay receipt-driven (W137).
Returns
The updated WO.
Business rules
- Header fields only. Output lines and the recipe snapshot are not edited here;
woNumberandworkSiteLocationIdare not patchable. - Status is patched directly. Any of the nine
org.wo_statusvalues is accepted; a validated manual-transition map is a v1 gap.Partial/Receivedare normally computed by the receipt workflow (W137). - Status drives the ledger. Step 3 reconciles FG
ORDER/DEMAND/ALLOCATEto the new status via the idempotent projector, writingREVERSE_*on backward or terminal (Cancelled) transitions.CONSUME/PRODUCEremain receipt-driven (W137), so the two paths don't double-count.
Errors
NotFoundError. The WO was not found.