W140: Update receipt
Edits a previously-recorded WO receipt. Triggered from Work Order Detail receipts section. Metadata-only edits are a fast path; any change to received quantities rebuilds the paired ledger entries and recomputes the WO status.
Steps
-
Load the receipt and parent WO. Call
WorkOrders.getReceiptById. -
Fast path for metadata-only edits. If only date or notes changed, call
WorkOrders.updateReceiptand return. -
Rebuild paired ledger entries on quantity edits. For the CONSUME (materials and FG, for sub-assembly inputs) and PRODUCE entries paired to this receipt (matched by
source_id = receipt.id), insert reverse entries to net them to zero. Then update the receipt header and items, and post fresh paired ledger entries via the same logic as W137 step 3. -
Recompute the WO status. Apply W137 step 4:
Receivedif every line is fully received,Partialotherwise.
Returns
The updated receipt.
Business rules
- Rebuild rather than patch. Step 3 deletes and re-inserts paired ledger entries; this keeps the consumption math consistent with the current snapshot and the receipt's quantities.
- Atomic. Steps 3 and 4 share one transaction.
Errors
NotFoundError. The receipt was not found.InvalidTransitionError. The parent WO is in a terminal status.