This proposal covers the scope of updating the purchase order item quantity on the basis of the saved search pending QTYS column value.
Requirement
Create a script that takes that item and subtracts the quantity from the “Pending Qty” column. So, if the order is 5 and the pending qty is 1, You delete one quantity from the order quantity field. When this is completed, the order will be marked as “PENDING BILLING”.
Our Solution
- To achieve the functionality, we will write a map-reduce script.
- Using the script, we will retrieve results from the saved search (search id: customsearch14302).
- We will group the search result based on the PO internal id. Because a single PO contains multiple items for processing.
- We will identify the items in PO using their SKU value.
- If the result SKU and item SKU are equal. We will compare the item quantity and Pending quantity value.
- We will deduct the pending QTYS item from the quantity order.
- If the deducted value is greater than -1, the deducted value will be used in place of the order quantity.
Sample scenario
- Order quantity = 3 and Pending QTYS = 2
Order quantity – Pending QTYS (3-2) = 1
1 will be set as a new order quantity.
- Order quantity = 2 and Pending QTYS = 3
Order quantity – Pending QTYS (2-3) = -1
We will not consider this item for updating the order quantity.
Following this change, the purchase order status will be pending billing and will be removed from the search.
Assumption
- We mapped the order items to the saved search results using item SKU.
- We assume that the PO does not have the same items on multiple lines.
Risk
- The update will directly need to work in production.
- We need 3 test purchase orders for the development. This order needs to be listed in the saved search.