Skip to content

Commit

Permalink
Merge pull request #875 from amansinghbais/#801
Browse files Browse the repository at this point in the history
Improved: code to handle duplicate shipmentIds while retrying shipping label and voiding label (#801)
  • Loading branch information
ravilodhi authored Dec 19, 2024
2 parents 99f2f8c + fd6e4f8 commit 962acf4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/components/GenerateTrackingCodeModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
4 changes: 3 additions & 1 deletion src/components/OrderLookupLabelActionsPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export default defineComponent({
const shippingLabelPdfUrls = [] as any;
shipmentPackages.map((shipmentPackage: any) => {
shipmentIds.push(shipmentPackage.shipmentId)
if(!shipmentIds.includes(shipmentPackage.shipmentId)) {
shipmentIds.push(shipmentPackage.shipmentId)
}
shipmentPackage.labelImageUrl && shippingLabelPdfUrls.push(shipmentPackage.labelImageUrl)
})
Expand Down
18 changes: 11 additions & 7 deletions src/components/ShippingLabelActionPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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."))
Expand Down
5 changes: 4 additions & 1 deletion src/views/Completed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,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) {
Expand Down
10 changes: 8 additions & 2 deletions src/views/OrderDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,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"))
Expand Down Expand Up @@ -1075,7 +1078,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);
Expand Down

0 comments on commit 962acf4

Please sign in to comment.