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

Support for multiple shipment packages (#801) #815

Merged
merged 6 commits into from
Oct 15, 2024
50 changes: 49 additions & 1 deletion src/services/UtilService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const findShipmentPackages = async(shipmentIds: Array<string>): Promise<any> =>
"shipmentId_op": "in"
},
"fieldList": ["shipmentId", "shipmentPackageSeqId", "shipmentRouteSegmentId", "shipmentMethodTypeId", "shipmentBoxTypeId", "packageName", "primaryOrderId", "carrierPartyId", "picklistBinId", "isTrackingRequired", "trackingCode", "internationalInvoiceUrl", "labelImageUrl", "carrierServiceStatusId"],
"viewSize": shipmentIds.length,
"viewSize": 250, //max size perform find support, need to update this logic to fetch the paginated detail
"distinct": "Y"
}

Expand Down Expand Up @@ -126,6 +126,53 @@ const findShipmentPackages = async(shipmentIds: Array<string>): Promise<any> =>
return shipmentPackages;
}

const findShipmentPackageContents = async (shipmentIds: Array<string>): Promise<any> => {
let viewIndex = 0;
let shipmentPackageContents: any[] = [];
let shipmentPackageContentInfo: { [key: string]: any[] } = {};
let resp;

try {
do {
resp = await api({
url: "performFind",
method: "get",
params: {
"entityName": "ShipmentPackageAndContent",
"inputFields": {
"shipmentId": shipmentIds,
"shipmentId_op": "in"
},
"fieldList": ["shipmentId", "shipmentItemSeqId", "shipmentPackageSeqId", "packageName", "quantity"],
viewIndex,
"viewSize": 250,
"distinct": "Y"
}
}) as any;

if (!hasError(resp) && resp.data.count) {
shipmentPackageContents = shipmentPackageContents.concat(resp.data.docs);
viewIndex++;
} else {
throw resp;
}
} while (resp.data.docs.length >= 250);
} catch (error) {
logger.error(error);
}

shipmentPackageContentInfo = shipmentPackageContents.reduce((contents: any, shipmentPackageContent: any) => {
if (contents[shipmentPackageContent.shipmentId]) {
contents[shipmentPackageContent.shipmentId].push(shipmentPackageContent);
} else {
contents[shipmentPackageContent.shipmentId] = [shipmentPackageContent];
}
return contents;
}, {});

return shipmentPackageContentInfo;
};


const findCarrierPartyIdsForShipment = async(shipmentIds: Array<string>): Promise<any> => {
let carrierPartyIdsByShipment = {};
Expand Down Expand Up @@ -578,6 +625,7 @@ export const UtilService = {
findShipmentIdsForOrders,
findShipmentItemInformation,
findShipmentPackages,
findShipmentPackageContents,
fetchTransferOrderFacets,
getAvailablePickers,
getProductStoreSetting,
Expand Down
33 changes: 21 additions & 12 deletions src/store/modules/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

// TODO: handle case when shipmentIds is empty
// https://stackoverflow.com/questions/28066429/promise-all-order-of-resolved-values
const [shipmentPackagesByOrderInformationAndPicklistBin, itemInformationByOrderInformation, carrierPartyIdsByShipmentInformation] = await Promise.all([UtilService.findShipmentPackages(orderShipmentIds), UtilService.findShipmentItemInformation(orderShipmentIds), UtilService.findCarrierPartyIdsForShipment(orderShipmentIds)])
const [shipmentPackagesByOrderInformationAndPicklistBin, shipmentPackageContents, itemInformationByOrderInformation, carrierPartyIdsByShipmentInformation] = await Promise.all([UtilService.findShipmentPackages(orderShipmentIds), UtilService.findShipmentPackageContents(orderShipmentIds), UtilService.findShipmentItemInformation(orderShipmentIds), UtilService.findCarrierPartyIdsForShipment(orderShipmentIds)])

// TODO: try fetching the carrierPartyIds when fetching packages information, as ShipmentPackageRouteSegDetail entity contain carrierPartyIds as well
const carrierPartyIds = [...new Set(Object.values(carrierPartyIdsByShipmentInformation).map((carrierPartyIds: any) => carrierPartyIds.map((carrier: any) => carrier.carrierPartyId)).flat())]
Expand Down Expand Up @@ -88,8 +88,8 @@
item.shipmentId = shipment.shipmentId
item.shipmentItemSeqId = shipment.shipmentItemSeqId
}

item.selectedBox = shipmentPackagesByOrderAndPicklistBin[`${item.orderId}_${item.picklistBinId}`]?.find((shipmentPackage: any) => shipmentPackage.shipmentId === item.shipmentId)?.packageName
item.selectedBox = shipmentPackageContents[`${item.shipmentId}`].find((shipmentPackageContent: any) => shipmentPackageContent.shipmentItemSeqId === item.shipmentItemSeqId)?.packageName
})

const orderItem = order.items[0];
Expand Down Expand Up @@ -240,7 +240,7 @@
commit(types.ORDER_COMPLETED_UPDATED, { list: completedOrders, total: state.completed.total })
},

async fetchGiftCardActivationDetails({ commit, state }, { isDetailsPage, currentOrders }) {

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

Check warning on line 243 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
const orders = JSON.parse(JSON.stringify(currentOrders));
const orderIds = [] as any;
let giftCardActivations = [] as any;
Expand Down Expand Up @@ -647,17 +647,26 @@
const missingLabelImage = this.state.util.productStoreShipmentMethCount > 0 ? shipmentPackageValues.some((shipmentPackage:any) => !shipmentPackage.trackingCode) : false;

const updateShipmentPackages = (order:any) => {
order.shipmentPackages.forEach((shipmentPackage:any) => {

const updatedShipmentPackages = order.shipmentPackages.reduce((updatedShipmentPackages: any[], shipmentPackage: any) => {
const key = `${shipmentPackage.shipmentId}-${shipmentPackage.shipmentPackageSeqId}`;
const updatedShipmentPackage = shipmentPackagesMap[key];

// Only add the shipment package if updatedShipmentPackage exists
if (updatedShipmentPackage) {
shipmentPackage.trackingCode = updatedShipmentPackage.trackingCode;
shipmentPackage.labelPdfUrl = updatedShipmentPackage.labelPdfUrl;
shipmentPackage.shipmentMethodTypeId = updatedShipmentPackage.shipmentMethodTypeId;
shipmentPackage.carrierPartyId = updatedShipmentPackage.carrierPartyId;
shipmentPackage.missingLabelImage = missingLabelImage;
const newShipmentPackage = { ...shipmentPackage };
newShipmentPackage.trackingCode = updatedShipmentPackage.trackingCode;
newShipmentPackage.labelPdfUrl = updatedShipmentPackage.labelPdfUrl;
newShipmentPackage.shipmentMethodTypeId = updatedShipmentPackage.shipmentMethodTypeId;
newShipmentPackage.carrierPartyId = updatedShipmentPackage.carrierPartyId;
newShipmentPackage.missingLabelImage = missingLabelImage;
updatedShipmentPackages.push(newShipmentPackage);
}
});

return updatedShipmentPackages;
}, []);

order.shipmentPackages = updatedShipmentPackages
order.trackingCode = order.shipmentPackages?.[0]?.trackingCode
order.missingLabelImage = missingLabelImage
};
Expand Down Expand Up @@ -1083,7 +1092,7 @@

// TODO: handle case when shipmentIds is empty
// https://stackoverflow.com/questions/28066429/promise-all-order-of-resolved-values
const [shipmentPackagesByOrderInformationAndPicklistBin, itemInformationByOrderInformation, carrierPartyIdsByShipmentInformation] = await Promise.all([UtilService.findShipmentPackages(orderShipmentIds), UtilService.findShipmentItemInformation(orderShipmentIds), UtilService.findCarrierPartyIdsForShipment(orderShipmentIds)])
const [shipmentPackagesByOrderInformationAndPicklistBin, shipmentPackageContents, itemInformationByOrderInformation, carrierPartyIdsByShipmentInformation] = await Promise.all([UtilService.findShipmentPackages(orderShipmentIds), UtilService.findShipmentPackageContents(orderShipmentIds), UtilService.findShipmentItemInformation(orderShipmentIds), UtilService.findCarrierPartyIdsForShipment(orderShipmentIds)])

// TODO: try fetching the carrierPartyIds when fetching packages information, as ShipmentPackageRouteSegDetail entity contain carrierPartyIds as well
const carrierPartyIds = [...new Set(Object.values(carrierPartyIdsByShipmentInformation).map((carrierPartyIds: any) => carrierPartyIds.map((carrier: any) => carrier.carrierPartyId)).flat())]
Expand Down Expand Up @@ -1133,7 +1142,7 @@
item.shipmentItemSeqId = shipment.shipmentItemSeqId
}

item.selectedBox = shipmentPackagesByOrderAndPicklistBin[`${item.orderId}_${item.picklistBinId}`]?.find((shipmentPackage: any) => shipmentPackage.shipmentId === item.shipmentId)?.packageName
item.selectedBox = shipmentPackageContents[`${item.shipmentId}`].find((shipmentPackageContent: any) => shipmentPackageContent.shipmentItemSeqId === item.shipmentItemSeqId)?.packageName
})

const orderItem = current.items[0];
Expand Down
3 changes: 2 additions & 1 deletion src/views/InProgress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ export default defineComponent({
}
} else {
prefix = 'rtp'
form.append(`${prefix}_newShipmentId_${index}`, shipmentPackage.shipmentId)
form.append(`${prefix}_newShipmentId_${index}`, shipmentPackage.shipmentId + "-" + shipmentPackage.shipmentPackageSeqId)
form.append(`${prefix}_shipmentId_${index}`, item.shipmentId)
form.append(`${prefix}_shipmentItemSeqId_${index}`, item.shipmentItemSeqId)
form.append(`${index}_${prefix}_rowSubmit_`, ''+index)
Expand Down Expand Up @@ -848,6 +848,7 @@ export default defineComponent({
order.items = items

await this.store.dispatch('order/updateInProgressOrder', order)
await this.store.dispatch('order/updateShipmentPackageDetail', order)
}
showToast(translate('Order updated successfully'))
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/views/OrderDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ export default defineComponent({
}
} else {
prefix = 'rtp'
form.append(`${prefix}_newShipmentId_${index}`, shipmentPackage.shipmentId)
form.append(`${prefix}_newShipmentId_${index}`, shipmentPackage.shipmentId + "-" + shipmentPackage.shipmentPackageSeqId)
form.append(`${prefix}_shipmentId_${index}`, item.shipmentId)
form.append(`${prefix}_shipmentItemSeqId_${index}`, item.shipmentItemSeqId)
form.append(`${index}_${prefix}_rowSubmit_`, ''+index)
Expand Down Expand Up @@ -1319,6 +1319,7 @@ export default defineComponent({

order.isModified = false;
await this.store.dispatch('order/updateInProgressOrder', order)
await this.store.dispatch('order/updateShipmentPackageDetail', order)
showToast(translate('Order updated successfully'))
return Promise.resolve(order);
} else {
Expand Down
Loading