Skip to content

Commit

Permalink
Merge pull request #815 from hotwax/#801_multiple_shipment_package
Browse files Browse the repository at this point in the history
Support for multiple shipment packages (#801)
  • Loading branch information
ravilodhi authored Oct 15, 2024
2 parents 23258a0 + 296956a commit c203e7a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 15 deletions.
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 @@ const actions: ActionTree<OrderState, RootState> = {

// 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 @@ const actions: ActionTree<OrderState, RootState> = {
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 @@ -647,17 +647,26 @@ const actions: ActionTree<OrderState, RootState> = {
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 @@ const actions: ActionTree<OrderState, RootState> = {

// 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 @@ const actions: ActionTree<OrderState, RootState> = {
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

0 comments on commit c203e7a

Please sign in to comment.