Skip to content

Commit

Permalink
Improved: logic to update state on closing PO items status(#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
amansinghbais committed Mar 14, 2024
1 parent 70885d4 commit e70039e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/components/ClosePurchaseOrderModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export default defineComponent({
getProduct: 'product/getProduct',
getPOItemAccepted: 'order/getPOItemAccepted',
order: 'order/getCurrent',
productIdentificationPref: 'user/getProductIdentificationPref'
productIdentificationPref: 'user/getProductIdentificationPref',
purchaseOrders: 'order/getPurchaseOrders'
})
},
props: ['isEligibileForCreatingShipment'],
Expand Down Expand Up @@ -125,6 +126,7 @@ export default defineComponent({
async updatePOItemStatus() {
// Shipment can only be created if quantity is specified for atleast one PO item.
// In some cases we don't need to create shipment instead directly need to close PO items.
if(this.isEligibileForCreatingShipment) {
const eligibleItemsForShipment = this.order.items.filter((item: any) => item.quantityAccepted > 0)
await this.store.dispatch('order/createPurchaseShipment', { items: eligibleItemsForShipment, orderId: this.order.orderId })
Expand All @@ -137,11 +139,42 @@ export default defineComponent({
orderItemSeqId: item.orderItemSeqId,
statusId: "ITEM_COMPLETED"
})
return item.orderItemSeqId
}))
const failedItemsCount = responses.filter((response) => response.status === 'rejected').length
if(failedItemsCount){
console.error('Failed to update the status of purchase order items.')
}
const completedItems = responses.filter((response) => response.status === 'fulfilled')?.map((response: any) => response.value)
if(!completedItems.length) return;
this.order.items.map((item: any) => {
if(completedItems.includes(item.orderItemSeqId)) {
item.orderItemStatusId = "ITEM_COMPLETED"
}
})
this.store.dispatch("order/updateCurrentOrder", this.order)
if(this.purchaseOrders.length) {
let purchaseOrders = JSON.parse(JSON.stringify(this.purchaseOrders))
const currentOrder = purchaseOrders.find((purchaseOrder: any) => purchaseOrder.groupValue === this.order.orderId)
let isPOCompleted = true;
currentOrder.doclist.docs.map((item: any) => {
if(completedItems.includes(item.orderItemSeqId)) {
item.orderItemStatusId = "ITEM_COMPLETED"
} else if(item.orderItemStatusId !== "ITEM_COMPLETED" || item.orderItemStatusId !== "ITEM_REJECTED") {
isPOCompleted = false
}
})
if(isPOCompleted) {
purchaseOrders = purchaseOrders.filter((purchaseOrder: any) => purchaseOrder.groupValue !== currentOrder.groupValue)
}
this.store.dispatch("order/updatePurchaseOrders", { purchaseOrders })
}
},
isEligibleToClosePOItems() {
return this.order.items.some((item: any) => item.isChecked && this.isPOItemStatusPending(item))
Expand Down
9 changes: 9 additions & 0 deletions src/store/modules/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,20 @@ const actions: ActionTree<OrderState, RootState> = {
}
commit(types.ORDER_CURRENT_UPDATED, state.current)
},
updateCurrentOrder({ state, commit }, payload) {

Check warning on line 212 in src/store/modules/order/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'state' is defined but never used

Check warning on line 212 in src/store/modules/order/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'state' is defined but never used
commit(types.ORDER_CURRENT_UPDATED, payload)
},
clearPurchaseOrders({commit}){
commit(types.ORDER_PRCHS_ORDRS_UPDATED, {
list: [],
total: 0
})
},
updatePurchaseOrders({commit, state}, payload){
commit(types.ORDER_PRCHS_ORDRS_UPDATED, {
list: payload.purchaseOrders,
total: payload.total ? payload.total : state.purchaseOrders.total
})
}
}

Expand Down

0 comments on commit e70039e

Please sign in to comment.