From e70039e7a71e2acce17a15053febe3c85d312cc3 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Thu, 14 Mar 2024 11:33:23 +0530 Subject: [PATCH 1/4] Improved: logic to update state on closing PO items status(#342) --- src/components/ClosePurchaseOrderModal.vue | 35 +++++++++++++++++++++- src/store/modules/order/actions.ts | 9 ++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/components/ClosePurchaseOrderModal.vue b/src/components/ClosePurchaseOrderModal.vue index 6f9e6fe1..a5be6287 100644 --- a/src/components/ClosePurchaseOrderModal.vue +++ b/src/components/ClosePurchaseOrderModal.vue @@ -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'], @@ -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 }) @@ -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)) diff --git a/src/store/modules/order/actions.ts b/src/store/modules/order/actions.ts index 513741fe..25c82fa0 100644 --- a/src/store/modules/order/actions.ts +++ b/src/store/modules/order/actions.ts @@ -209,11 +209,20 @@ const actions: ActionTree = { } commit(types.ORDER_CURRENT_UPDATED, state.current) }, + updateCurrentOrder({ state, commit }, payload) { + 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 + }) } } From e91aff4196cdef9e7709c9a0a388e57d4726794e Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Thu, 14 Mar 2024 11:40:50 +0530 Subject: [PATCH 2/4] Reverted: unnecessary space added in the code (#342) --- src/components/ClosePurchaseOrderModal.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/ClosePurchaseOrderModal.vue b/src/components/ClosePurchaseOrderModal.vue index a5be6287..c9187ca0 100644 --- a/src/components/ClosePurchaseOrderModal.vue +++ b/src/components/ClosePurchaseOrderModal.vue @@ -126,7 +126,6 @@ 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 }) From f6bad4ba1332d5ede2129c553759e8c8e1e85b25 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Thu, 14 Mar 2024 16:01:03 +0530 Subject: [PATCH 3/4] Reverted: unused state in the updateCurrentOrder action (#342) --- src/store/modules/order/actions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/modules/order/actions.ts b/src/store/modules/order/actions.ts index 25c82fa0..7a2b95f2 100644 --- a/src/store/modules/order/actions.ts +++ b/src/store/modules/order/actions.ts @@ -209,7 +209,7 @@ const actions: ActionTree = { } commit(types.ORDER_CURRENT_UPDATED, state.current) }, - updateCurrentOrder({ state, commit }, payload) { + updateCurrentOrder({ commit }, payload) { commit(types.ORDER_CURRENT_UPDATED, payload) }, clearPurchaseOrders({commit}){ From 3a553fc966c356cfb775ded3fe036c444ff40b02 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Thu, 14 Mar 2024 18:21:59 +0530 Subject: [PATCH 4/4] Fixed: logical operator for checking whether item is pending or not (#342) --- src/components/ClosePurchaseOrderModal.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ClosePurchaseOrderModal.vue b/src/components/ClosePurchaseOrderModal.vue index c9187ca0..a0079cc5 100644 --- a/src/components/ClosePurchaseOrderModal.vue +++ b/src/components/ClosePurchaseOrderModal.vue @@ -164,7 +164,7 @@ export default defineComponent({ 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") { + } else if(item.orderItemStatusId !== "ITEM_COMPLETED" && item.orderItemStatusId !== "ITEM_REJECTED") { isPOCompleted = false } })