W146: Get sales order detail
Returns a single SO with everything the detail page needs: header, items, SKUs, timeline notes, documents, and a computed fulfillment status derived from the FG ledger. Triggered by clicking an SO in the list.
Steps
-
Load the SO header. Call
SalesOrders.getSoById. -
Load items and hydrate SKUs. Call
SalesOrders.listItemsBySoandProducts.getSkusByIdsfor the referenced SKUs. -
Derive the computed fulfillment status. For each line, sum CONSUME quantities from the FG ledger via
listEntries({ refLike: soNumber, eventType: 'CONSUME' }); compare against expected to derivePending,Partial, orFulfilled. -
Return both computed and stored fulfillment status. When they differ, the page surfaces the computed value and keeps the stored value visible as the "user-set override" indicator.
-
Load timeline notes and documents.
SalesOrders.listTimelineNotesBySoandDocuments.listByEntity('sales_order', soId).
Returns
The merged hydrated view: header plus items plus SKUs plus computed fulfillment status plus timeline notes plus documents.
Business rules
- Computed vs. stored fulfillment status is deliberate. The ledger is the source of truth, but a manual override gives sales ops a release valve when reality diverges from the data. A future iteration may collapse the two into a derived-only field.
Errors
NotFoundError. The SO was not found.