W117: Add item to purchase order
Appends a new line to an existing PO. Triggered from the Purchase Order Detail items section.
Steps
-
Load the PO. Call
PurchaseOrders.getPoByIdto confirm existence and readtargetTypeandstatus. -
Assert editable. 409 when any receipt exists against the PO — line items are locked once goods have been received (same rule as WO items, W134-W136).
-
Validate the catalog reference. Confirm the referenced material or SKU exists in this org, matches
targetType, and is active. -
Insert the line. Call
PurchaseOrders.addItemwith quantity and unit cost. -
Project the new line. Run the status → ledger reconciliation projector for just this line — past
Planningit books the line's ORDER;Planning/Cancelledbook nothing.
Returns
The new line.
Business rules
- Items are locked once a receipt exists. Receipts roll header costs up from the lines; editing partly-received orders would corrupt the math.
- Catalog must match
targetType. A materials PO accepts only materials; an FG PO accepts only SKUs. - Active references only. Soft-deleted materials or SKUs cannot be added.
Errors
NotFoundError. The PO, material, or SKU was not found.ConflictError. A receipt exists against the PO.ValidationError. The referenced catalog mismatches the PO's target type.