Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved: logic to update state on closing PO items status(#342) #360

Merged
merged 4 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 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 @@ -137,11 +138,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 @@ -111,7 +111,7 @@
}
return resp;
},
async createPurchaseShipment({ commit }, payload) {

Check warning on line 114 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)

'commit' is defined but never used

Check warning on line 114 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)

'commit' is defined but never used
let resp;
try {
const params = {
Expand Down Expand Up @@ -209,11 +209,20 @@
}
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
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading