Skip to content

Commit

Permalink
Fixed: Fetched shipment contents in order to display the correct box …
Browse files Browse the repository at this point in the history
…for each item (#801).
  • Loading branch information
ravilodhi committed Oct 10, 2024
1 parent 4017362 commit be4ec40
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
48 changes: 48 additions & 0 deletions src/services/UtilService.ts
Original file line number Diff line number Diff line change
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
9 changes: 5 additions & 4 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 @@ -1083,7 +1083,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,6 +1133,7 @@ const actions: ActionTree<OrderState, RootState> = {
item.shipmentItemSeqId = shipment.shipmentItemSeqId
}

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

Expand Down

0 comments on commit be4ec40

Please sign in to comment.