From 2d914e4bbfbecab047d308b82a3a4c5232203fec Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Wed, 11 Dec 2024 16:44:17 +0530 Subject: [PATCH 1/3] Improved: code to handle duplicate shipmentIds while retrying shipping label and voiding label (#801) --- src/components/GenerateTrackingCodeModal.vue | 5 ++++- .../OrderLookupLabelActionsPopover.vue | 6 ++++-- src/components/ShippingLabelActionPopover.vue | 18 +++++++++++------- src/views/Completed.vue | 5 ++++- src/views/OrderDetail.vue | 10 ++++++++-- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/components/GenerateTrackingCodeModal.vue b/src/components/GenerateTrackingCodeModal.vue index 456dfe66..091dfa19 100644 --- a/src/components/GenerateTrackingCodeModal.vue +++ b/src/components/GenerateTrackingCodeModal.vue @@ -209,7 +209,10 @@ export default defineComponent({ // Getting all the shipmentIds from shipmentPackages for which label is missing const shipmentIds = order.shipmentPackages ?.filter((shipmentPackage: any) => !shipmentPackage.trackingCode) - .map((shipmentPackage: any) => shipmentPackage.shipmentId); + .reduce((uniqueIds: any[], shipmentPackage: any) => { + if(!uniqueIds.includes(shipmentPackage.shipmentId)) uniqueIds.push(shipmentPackage.shipmentId); + return uniqueIds; + }, []); if(!shipmentIds?.length) { showToast(translate("Failed to generate shipping label")) diff --git a/src/components/OrderLookupLabelActionsPopover.vue b/src/components/OrderLookupLabelActionsPopover.vue index 01bd8e6b..dd8b853e 100644 --- a/src/components/OrderLookupLabelActionsPopover.vue +++ b/src/components/OrderLookupLabelActionsPopover.vue @@ -51,8 +51,10 @@ export default defineComponent({ const shippingLabelPdfUrls = [] as any; shipmentPackages.map((shipmentPackage: any) => { - shipmentIds.push(shipmentPackage.shipmentId) - shippingLabelPdfUrls.push(shipmentPackage.labelImageUrl) + if(!shipmentIds.includes(shipmentPackage.shipmentId)) { + shipmentIds.push(shipmentPackage.shipmentId) + shippingLabelPdfUrls.push(shipmentPackage.labelImageUrl) + } }) await OrderService.printShippingLabel(shipmentIds, shippingLabelPdfUrls) diff --git a/src/components/ShippingLabelActionPopover.vue b/src/components/ShippingLabelActionPopover.vue index 2f32a7fa..bff9cff7 100644 --- a/src/components/ShippingLabelActionPopover.vue +++ b/src/components/ShippingLabelActionPopover.vue @@ -61,16 +61,20 @@ popoverController.dismiss() }, async voidShippingLabel(order: any) { + const shipmentIds = [] as any; let resp = {} as any; try { for (const shipmentPackage of order.shipmentPackages) { - resp = await OrderService.voidShipmentLabel({ - "shipmentId": shipmentPackage.shipmentId, - "shipmentRouteSegmentId": shipmentPackage.shipmentRouteSegmentId - }) - - if(hasError(resp)) { - throw resp.data; + if(!shipmentIds.includes(shipmentPackage.shipmentId)) { + resp = await OrderService.voidShipmentLabel({ + "shipmentId": shipmentPackage.shipmentId, + "shipmentRouteSegmentId": shipmentPackage.shipmentRouteSegmentId + }) + + if(hasError(resp)) { + throw resp.data; + } + shipmentIds.push(shipmentPackage.shipmentId); } } showToast(translate("Shipping label voided successfully.")) diff --git a/src/views/Completed.vue b/src/views/Completed.vue index fe072cd2..c9db83cc 100644 --- a/src/views/Completed.vue +++ b/src/views/Completed.vue @@ -637,7 +637,10 @@ export default defineComponent({ // Getting all the shipmentIds from shipmentPackages for which label is missing const shipmentIds = order.shipmentPackages ?.filter((shipmentPackage: any) => !shipmentPackage.trackingCode) - .map((shipmentPackage: any) => shipmentPackage.shipmentId); + .reduce((uniqueIds: any[], shipmentPackage: any) => { + if(!uniqueIds.includes(shipmentPackage.shipmentId)) uniqueIds.push(shipmentPackage.shipmentId); + return uniqueIds; + }, []); // Don't make any api call when we does not have any shipmentIds for order if(!shipmentIds?.length) { diff --git a/src/views/OrderDetail.vue b/src/views/OrderDetail.vue index 0f0b0a67..f76ca8cf 100644 --- a/src/views/OrderDetail.vue +++ b/src/views/OrderDetail.vue @@ -1042,7 +1042,10 @@ export default defineComponent({ // Getting all the shipmentIds from shipmentPackages for which label is missing const shipmentIds = order.shipmentPackages ?.filter((shipmentPackage: any) => !shipmentPackage.trackingCode) - .map((shipmentPackage: any) => shipmentPackage.shipmentId); + .reduce((uniqueIds: any[], shipmentPackage: any) => { + if(!uniqueIds.includes(shipmentPackage.shipmentId)) uniqueIds.push(shipmentPackage.shipmentId); + return uniqueIds; + }, []); if(!shipmentIds?.length) { showToast(translate("Failed to generate shipping label")) @@ -1076,7 +1079,10 @@ export default defineComponent({ return popover.present(); }, async printShippingLabel(order: any) { - const shipmentIds = order.shipmentIds ? order.shipmentIds : order.shipmentPackages?.map((shipmentPackage: any) => shipmentPackage.shipmentId); + const shipmentIds = order.shipmentIds ? order.shipmentIds : order.shipmentPackages?.reduce((uniqueIds: any[], shipmentPackage: any) => { + if(!uniqueIds.includes(shipmentPackage.shipmentId)) uniqueIds.push(shipmentPackage.shipmentId); + return uniqueIds; + }, []);; const shippingLabelPdfUrls = order.shipmentPackages ?.filter((shipmentPackage: any) => shipmentPackage.labelPdfUrl) .map((shipmentPackage: any) => shipmentPackage.labelPdfUrl); From ebe53c678b2900cbc8a35641b17847b27a67eca9 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Wed, 11 Dec 2024 16:45:35 +0530 Subject: [PATCH 2/3] Reverted: unwanted semi colon in the details page (#801) --- src/views/OrderDetail.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/OrderDetail.vue b/src/views/OrderDetail.vue index f76ca8cf..73990806 100644 --- a/src/views/OrderDetail.vue +++ b/src/views/OrderDetail.vue @@ -1082,7 +1082,7 @@ export default defineComponent({ const shipmentIds = order.shipmentIds ? order.shipmentIds : order.shipmentPackages?.reduce((uniqueIds: any[], shipmentPackage: any) => { if(!uniqueIds.includes(shipmentPackage.shipmentId)) uniqueIds.push(shipmentPackage.shipmentId); return uniqueIds; - }, []);; + }, []); const shippingLabelPdfUrls = order.shipmentPackages ?.filter((shipmentPackage: any) => shipmentPackage.labelPdfUrl) .map((shipmentPackage: any) => shipmentPackage.labelPdfUrl); From 803b3360c88caff0b1810f4c0db2d0b1ac5e5a33 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Wed, 11 Dec 2024 19:17:42 +0530 Subject: [PATCH 3/3] Fixed: logic to print shipping label in case of orderLookup (#801) --- src/components/OrderLookupLabelActionsPopover.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/OrderLookupLabelActionsPopover.vue b/src/components/OrderLookupLabelActionsPopover.vue index dd8b853e..312d7001 100644 --- a/src/components/OrderLookupLabelActionsPopover.vue +++ b/src/components/OrderLookupLabelActionsPopover.vue @@ -53,8 +53,8 @@ export default defineComponent({ shipmentPackages.map((shipmentPackage: any) => { if(!shipmentIds.includes(shipmentPackage.shipmentId)) { shipmentIds.push(shipmentPackage.shipmentId) - shippingLabelPdfUrls.push(shipmentPackage.labelImageUrl) } + shippingLabelPdfUrls.push(shipmentPackage.labelImageUrl) }) await OrderService.printShippingLabel(shipmentIds, shippingLabelPdfUrls)