W133: Delete work order
Wipes a WO and every inventory effect it produced on both the materials and FG ledgers. Triggered from Work Order Detail.
Steps
-
Load the WO. Call
WorkOrders.getWoById. -
Gather the WO's source ids. Before anything cascades, list the WO's items (
wo_item), its input snapshots (wo_input), and its receipts' items (wo_receipt). -
Physically delete the WO's ledger rows. Call
deleteBySourceon both ledgers forwo_item(the status-driven FGORDER),wo_input(the inputDEMAND/ALLOCATE), andwo_receipt(the receipt-drivenCONSUME/PRODUCE). The rows are removed outright. Because every row tied to a line shares its source id, deleting by(source_type, source_id)sweeps forward, reverse, and edit-trail rows alike. -
Detach documents. Call
Documents.listByEntity('work_order', woId)andDocuments.deletefor each. -
Delete the WO row. Call
WorkOrders.deleteWo. Items, inputs (recipe snapshot), receipts, and receipt items cascade away at the DB layer.
Returns
Nothing.
Business rules
- Hard delete, not reversal. Deleting the WO removes its ledger rows entirely — the record never happened. Cancellation (W132, status →
Cancelled) is the append-only path that reverses and keeps the audit trail. - Atomic across both ledgers and the row delete. Steps 3 through 5 share a single transaction.
- Deleting produced-and-shipped inventory leaves the SO side hanging. Removing a WO's
PRODUCErows can drop FG on-hand below what a downstream SO already consumed. Practical guidance: do not delete WOs that have produced shipped inventory; cancel instead. - Allowed at any status. Hard delete is rare; cancellation (W132) is the routine path.
Errors
NotFoundError. The WO was not found.