From 26e0d38647bd742e5e91f331229cc58c43e07f18 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Fri, 11 Oct 2024 16:57:53 +0530 Subject: [PATCH 1/5] Improved: making receipt shipment items in sync instead of using async (#390) --- src/store/modules/shipment/actions.ts | 94 ++++++++++++++++----------- src/views/ShipmentDetails.vue | 9 +-- 2 files changed, 62 insertions(+), 41 deletions(-) diff --git a/src/store/modules/shipment/actions.ts b/src/store/modules/shipment/actions.ts index efbbcd49..7bc954bc 100644 --- a/src/store/modules/shipment/actions.ts +++ b/src/store/modules/shipment/actions.ts @@ -49,7 +49,7 @@ const actions: ActionTree = { const item = state.current.items.find((item: any) => { const itemVal = barcodeIdentifier ? getProductIdentificationValue(barcodeIdentifier, getProduct(item.productId)) : item.internalName; - return itemVal === payload; + return itemVal === payload && item.quantityReceived === 0; }); if (item) { @@ -75,6 +75,7 @@ const actions: ActionTree = { const locationSeqId = facilityLocations[0].locationSeqId resp.data.items.map((item: any) => { item.locationSeqId = locationSeqId; + item.quantityReceived = item.quantityAccepted ? Number(item.quantityAccepted) : 0 }); } else { showToast(translate("Facility locations were not found corresponding to destination facility of return shipment. Please add facility locations to avoid receive return shipment failure.")) @@ -101,48 +102,67 @@ const actions: ActionTree = { return Promise.reject(new Error(err)) } }, - receiveShipmentItem ({ commit }, payload) { - return Promise.all(payload.items.map(async (item: any) => { - if(!item.locationSeqId) { - return Promise.reject("Missing locationSeqId on item") - } + async receiveShipmentItem ({ commit }, payload) { + const responses = []; + + for (const item of payload.items) { + if(item.quantityReceived === 0) { + if (!item.locationSeqId) { + console.error("Missing locationSeqId on item"); + responses.push(false); + continue; + } + + const params = { + shipmentId: payload.shipmentId, + facilityId: this.state.user.currentFacility.facilityId, + shipmentItemSeqId: item.itemSeqId, + productId: item.productId, + quantityAccepted: item.quantityAccepted, + orderId: item.orderId, + orderItemSeqId: item.orderItemSeqId, + unitCost: 0.00, + locationSeqId: item.locationSeqId + } - const params = { - shipmentId: payload.shipmentId, - facilityId: this.state.user.currentFacility.facilityId, - shipmentItemSeqId: item.itemSeqId, - productId: item.productId, - quantityAccepted: item.quantityAccepted, - orderId: item.orderId, - orderItemSeqId: item.orderItemSeqId, - unitCost: 0.00, - locationSeqId: item.locationSeqId + try { + const resp = await ShipmentService.receiveShipmentItem(params) + if(resp.status === 200 && !hasError(resp)){ + responses.push(true) + } else { + throw resp.data; + } + } catch(error: any) { + responses.push(false) + } } - const resp = await ShipmentService.receiveShipmentItem(params) - if(resp.status === 200 && !hasError(resp)){ - return Promise.resolve(resp); - } else { - return Promise.reject(resp); - } - })) + } + + return responses; }, async receiveShipment ({ dispatch }, payload) { emitter.emit("presentLoader"); - return await dispatch("receiveShipmentItem", payload).then(async () => { - const resp = await ShipmentService.receiveShipment({ - "shipmentId": payload.shipmentId, - "statusId": "PURCH_SHIP_RECEIVED" - }) - if (resp.status == 200 && !hasError(resp)) { - showToast(translate("Shipment received successfully", { shipmentId: payload.shipmentId })) + const receiveResponses = await dispatch("receiveShipmentItem", payload); + if(!receiveResponses.includes(false)) { + try { + const resp = await ShipmentService.receiveShipment({ + "shipmentId": payload.shipmentId, + "statusId": "PURCH_SHIP_RECEIVED" + }) + + if (resp.status == 200 && !hasError(resp)) { + showToast(translate("Shipment received successfully", { shipmentId: payload.shipmentId })) + emitter.emit("dismissLoader"); + return true; + } else { + throw resp.data; + } + } catch(error: any) { + console.error(error); } - emitter.emit("dismissLoader"); - return resp; - }).catch(err => { - emitter.emit("dismissLoader"); - console.error(err) - return err; - }); + } + emitter.emit("dismissLoader"); + return false; }, async addShipmentItem ({ state, commit, dispatch }, payload) { const item = payload.shipmentId ? { ...(payload.item) } : { ...payload } diff --git a/src/views/ShipmentDetails.vue b/src/views/ShipmentDetails.vue index 2497d3ba..48d16a5c 100644 --- a/src/views/ShipmentDetails.vue +++ b/src/views/ShipmentDetails.vue @@ -54,7 +54,7 @@
- +
@@ -66,7 +66,7 @@
- + {{ translate("Receive All") }} @@ -225,11 +225,12 @@ export default defineComponent({ async receiveShipment() { const eligibleItems = this.current.items.filter((item: any) => item.quantityAccepted > 0) const shipmentId = this.current.shipment ? this.current.shipment.shipmentId : this.current.shipmentId - const resp = await this.store.dispatch('shipment/receiveShipment', { items: eligibleItems, shipmentId }) - if (resp.status === 200 && !hasError(resp)) { + const isShipmentReceived = await this.store.dispatch('shipment/receiveShipment', { items: eligibleItems, shipmentId }) + if(isShipmentReceived) { this.router.push('/shipments'); } else { showToast(translate("Failed to receive shipment")) + this.store.dispatch('shipment/setCurrent', { shipmentId: this.$route.params.id }) } }, isEligibleForReceivingShipment() { From 854bb0adf3d9337959645987cf276a3430a94bf4 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Fri, 11 Oct 2024 17:02:40 +0530 Subject: [PATCH 2/5] Improved: loader message and backdrop dismiss config (#390) --- src/store/modules/shipment/actions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/modules/shipment/actions.ts b/src/store/modules/shipment/actions.ts index 7bc954bc..92efd806 100644 --- a/src/store/modules/shipment/actions.ts +++ b/src/store/modules/shipment/actions.ts @@ -141,7 +141,7 @@ const actions: ActionTree = { return responses; }, async receiveShipment ({ dispatch }, payload) { - emitter.emit("presentLoader"); + emitter.emit("presentLoader", {message: 'Receiving inprogress.', backdropDismiss: false}); const receiveResponses = await dispatch("receiveShipmentItem", payload); if(!receiveResponses.includes(false)) { try { From efcd53f26e1d12def0104ad097c0da550d74bd46 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Fri, 11 Oct 2024 19:17:08 +0530 Subject: [PATCH 3/5] Improved: logic for flagging error in api calls (#390) --- src/store/modules/shipment/actions.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/store/modules/shipment/actions.ts b/src/store/modules/shipment/actions.ts index 92efd806..bebdb4c7 100644 --- a/src/store/modules/shipment/actions.ts +++ b/src/store/modules/shipment/actions.ts @@ -103,13 +103,13 @@ const actions: ActionTree = { } }, async receiveShipmentItem ({ commit }, payload) { - const responses = []; + let areAllSuccess = true; for (const item of payload.items) { if(item.quantityReceived === 0) { if (!item.locationSeqId) { console.error("Missing locationSeqId on item"); - responses.push(false); + areAllSuccess = false; continue; } @@ -127,18 +127,16 @@ const actions: ActionTree = { try { const resp = await ShipmentService.receiveShipmentItem(params) - if(resp.status === 200 && !hasError(resp)){ - responses.push(true) - } else { + if(hasError(resp)){ throw resp.data; - } + } } catch(error: any) { - responses.push(false) + areAllSuccess = false } } } - return responses; + return areAllSuccess; }, async receiveShipment ({ dispatch }, payload) { emitter.emit("presentLoader", {message: 'Receiving inprogress.', backdropDismiss: false}); From ab415a9d7e2adf883dbd2973e966986a0d386396 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Fri, 11 Oct 2024 19:20:02 +0530 Subject: [PATCH 4/5] Improved: check for receive shipment and loader message (#390) --- src/store/modules/shipment/actions.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/store/modules/shipment/actions.ts b/src/store/modules/shipment/actions.ts index bebdb4c7..ffe4adb2 100644 --- a/src/store/modules/shipment/actions.ts +++ b/src/store/modules/shipment/actions.ts @@ -139,9 +139,9 @@ const actions: ActionTree = { return areAllSuccess; }, async receiveShipment ({ dispatch }, payload) { - emitter.emit("presentLoader", {message: 'Receiving inprogress.', backdropDismiss: false}); - const receiveResponses = await dispatch("receiveShipmentItem", payload); - if(!receiveResponses.includes(false)) { + emitter.emit("presentLoader", {message: 'Receiving in-progress.', backdropDismiss: false}); + const areAllSuccess = await dispatch("receiveShipmentItem", payload); + if(areAllSuccess) { try { const resp = await ShipmentService.receiveShipment({ "shipmentId": payload.shipmentId, From c0d3c38e9af5c82946f0073916bed54495b28e62 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Fri, 11 Oct 2024 19:25:03 +0530 Subject: [PATCH 5/5] Improved: allowing popover to open only if quantity is not received (#390) --- src/views/ShipmentDetails.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/ShipmentDetails.vue b/src/views/ShipmentDetails.vue index 48d16a5c..50ff3e44 100644 --- a/src/views/ShipmentDetails.vue +++ b/src/views/ShipmentDetails.vue @@ -46,7 +46,7 @@
- + {{ item.locationSeqId }}