W148: Delete sales order
Wipes an SO, detaches its document attachments, and removes every FG ledger effect it produced. Triggered from Sales Order Detail.
Steps
-
Load the SO. Call
SalesOrders.getSoById. -
Gather the SO's source ids. List the SO's items; each line's ledger rows are keyed by
source_type='so_item',source_id=soItemId. (SO has no receipts, so these are the only rows.) -
Physically delete the SO's ledger rows. Call
deleteBySource('so_item', itemIds)on both ledgers, removing the lineDEMAND/ALLOCATE/CONSUMErows outright. The rows are gone, not offset withREVERSE_*rows. -
Detach documents. Call
Documents.listByEntity('sales_order', soId)andDocuments.deletefor each, which removes the row and the GCS object. -
Delete the SO row. Call
SalesOrders.deleteSo. Items and timeline notes cascade away at the DB layer.
Returns
Nothing.
Business rules
- Hard delete, not reversal. Deleting the SO removes its ledger rows entirely — the record never happened. Cancellation (status →
Rejected) is the append-only path that reverses and keeps the audit trail. - Deleting a shipped SO drops the consumption. Removing a
CONSUMErow nets FG on-hand back up by the consumed quantity, which is a corrective action, not end-of-life. Once a shipment really happened, mark the SOCompletedrather than delete it.
Errors
NotFoundError. The SO was not found.