W121: Remove item from purchase order
Drops a PO line. Triggered from the Purchase Order Detail items section.
Steps
-
Load the line. Call
PurchaseOrders.getItemById; unknown ids raiseNotFoundError(no silent no-op). -
Assert editable. 409 when any receipt exists against the PO — line items are locked once goods have been received (same rule as WO items, W134-W136).
-
Delete the line's ledger rows FIRST. Removing a line is a hard delete, so call
deleteBySource('po_item', [itemId])on both ledgers to physically remove the line'sORDERrows — once the line row is gone its source id never reaches a reconcile again, so this has to happen first. -
Remove the line. Call
PurchaseOrders.removeItem.
Returns
Nothing.
Business rules
- Items are locked once a receipt exists. (Receipt items are keyed by material / SKU, not by PO line, so this is a business-level guard, not a DB constraint.)
- Delete-before-remove is load-bearing: the ledger rows must go before the line, or they strand. Removing a line physically deletes its rows (it never happened); cancelling the whole PO is the append-only path that reverses instead.
Errors
NotFoundError. The line was not found.ConflictError. A receipt exists against the PO.