W126: Delete receipt
Removes a receipt and the inventory effect it booked. Triggered from the Purchase Order Detail receipts section.
Steps
-
Load the receipt. Call
PurchaseOrders.getReceiptByIdto confirm existence and capture thepurchaseOrderId. -
Physically delete the receipt's ledger rows. Gather the receipt-item ids and call
deleteBySource('po_receipt', receiptItemIds)on both the materials and finished-goods ledgers, removing theRECEIVErows outright. This is a hard delete — the rows are gone, not reversed (contrast a cancellation, which stays append-only). Gathering happens before the receipt items cascade away. -
Delete the receipt row. Call
PurchaseOrders.deleteReceipt. The receipt items cascade away at the DB layer. -
Recompute the PO status. Recompute
Partial/Receivedfrom the surviving receipts, reverting toPlacedwhen no received quantity remains, so the PO never dangles asReceived/Partialwithout receipts behind it.
Returns
Nothing.
Business rules
- Hard delete, not reversal. The receipt never happened, so its ledger rows are removed rather than offset with
REVERSE_*rows. Cancellation is the append-only path that preserves history. - Status follows the surviving receipts. Deleting the last receipt returns the PO to
Placed. - Cost cascade is still a v1 gap. The PO header has no stored
costscolumn today (it is computed on read), so there is nothing to re-roll here. The downstream FIFO/cost cascade remains deferred with W122 steps 7-9.
Errors
NotFoundError. The receipt was not found.