Skip to main content
Version: v1.0.0(int)

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

  1. Load the SO. Call SalesOrders.getSoById.

  2. 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.)

  3. Physically delete the SO's ledger rows. Call deleteBySource('so_item', itemIds) on both ledgers, removing the line DEMAND/ALLOCATE/CONSUME rows outright. The rows are gone, not offset with REVERSE_* rows.

  4. Detach documents. Call Documents.listByEntity('sales_order', soId) and Documents.delete for each, which removes the row and the GCS object.

  5. 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 CONSUME row 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 SO Completed rather than delete it.

Errors

  • NotFoundError. The SO was not found.