From 766579f32a8736f5a16ca0fa2926b4be4a2ccd9d Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Thu, 13 Jul 2023 14:58:00 +0530 Subject: [PATCH 1/3] Fixed: issue of shipmentId not found on items, improved logic to create key when fetching shipment and shipment route information(#155) --- src/services/UtilService.ts | 18 ++++++++++-------- src/store/modules/order/actions.ts | 16 +++++++++++----- src/views/InProgress.vue | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/services/UtilService.ts b/src/services/UtilService.ts index 08551b67..dc67ac62 100644 --- a/src/services/UtilService.ts +++ b/src/services/UtilService.ts @@ -32,7 +32,7 @@ const findShipmentIdsForOrders = async(picklistBinIds: Array, orderIds: "statusId": statusId, "statusId_op": "in" }, - "fieldList": ["shipmentId", "primaryOrderId"], + "fieldList": ["shipmentId", "primaryOrderId", "picklistBinId"], "viewSize": 200, // maximum records we have for orders "distinct": "Y" } @@ -47,10 +47,11 @@ const findShipmentIdsForOrders = async(picklistBinIds: Array, orderIds: if (!hasError(resp)) { shipmentIdsForOrders = resp?.data.docs.reduce((shipmentIdsForOrders: any, shipment: any) => { - if(shipmentIdsForOrders[shipment.primaryOrderId]) { - shipmentIdsForOrders[shipment.primaryOrderId].push(shipment.shipmentId) + const key = `${shipment.primaryOrderId}_${shipment.picklistBinId}` + if(shipmentIdsForOrders[key]) { + shipmentIdsForOrders[key].push(shipment.shipmentId) } else { - shipmentIdsForOrders[shipment.primaryOrderId] = [shipment.shipmentId] + shipmentIdsForOrders[key] = [shipment.shipmentId] } return shipmentIdsForOrders }, {}) @@ -74,7 +75,7 @@ const findShipmentPackages = async(shipmentIds: Array): Promise => "shipmentId": shipmentIds, "shipmentId_op": "in" }, - "fieldList": ["shipmentId", "shipmentPackageSeqId", "shipmentBoxTypeId", "packageName", "primaryOrderId", "carrierPartyId"], + "fieldList": ["shipmentId", "shipmentPackageSeqId", "shipmentBoxTypeId", "packageName", "primaryOrderId", "carrierPartyId", "picklistBinId"], "viewSize": shipmentIds.length, "distinct": "Y" } @@ -88,10 +89,11 @@ const findShipmentPackages = async(shipmentIds: Array): Promise => if(resp?.status == 200 && !hasError(resp) && resp.data.count) { shipmentPackages = resp.data.docs.reduce((shipmentForOrders: any, shipmentPackage: any) => { - if(shipmentForOrders[shipmentPackage.primaryOrderId]) { - shipmentForOrders[shipmentPackage.primaryOrderId].push(shipmentPackage) + const key = `${shipmentPackage.primaryOrderId}_${shipmentPackage.picklistBinId}` + if(shipmentForOrders[key]) { + shipmentForOrders[key].push(shipmentPackage) } else { - shipmentForOrders[shipmentPackage.primaryOrderId] = [shipmentPackage] + shipmentForOrders[key] = [shipmentPackage] } return shipmentForOrders }, {}) diff --git a/src/store/modules/order/actions.ts b/src/store/modules/order/actions.ts index 68a6e401..7dea149d 100644 --- a/src/store/modules/order/actions.ts +++ b/src/store/modules/order/actions.ts @@ -66,7 +66,7 @@ const actions: ActionTree = { inProgressOrders = inProgressOrders.map((order: any) => { // if for an order shipment information is not available then returning the same order information again - if(!shipmentIdsForOrders[order.orderId]) { + if(!shipmentIdsForOrders[`${order.orderId}_${order.picklistBinId}`]) { // if there are no shipment for the order, there is some issue with the order if (picklistBinIds.includes(order.picklistBinId) && orderIds.includes(order.orderId)) { return { @@ -79,8 +79,14 @@ const actions: ActionTree = { order.items.map((item: any) => { // fetching shipmentItemInformation for the current order item and then assigning the shipmentItemSeqId to item - item.shipmentItemSeqId = itemInformationByOrder[item.orderId]?.find((shipmentItem: any) => shipmentItem.orderItemSeqId === item.orderItemSeqId)?.shipmentItemSeqId - item.selectedBox = shipmentPackagesByOrder[item.orderId]?.find((shipmentPackage: any) => shipmentPackage.shipmentId === item.shipmentId)?.packageName + const shipment = itemInformationByOrder[item.orderId]?.find((shipmentItem: any) => shipmentItem.orderItemSeqId === item.orderItemSeqId) + + if(shipment) { + item.shipmentId = shipment.shipmentId + item.shipmentItemSeqId = shipment.shipmentItemSeqId + } + + item.selectedBox = shipmentPackagesByOrder[`${item.orderId}_${item.picklistBinId}`]?.find((shipmentPackage: any) => shipmentPackage.shipmentId === item.shipmentId)?.packageName }) const orderItem = order.items[0]; @@ -88,8 +94,8 @@ const actions: ActionTree = { return { ...order, - shipmentIds: shipmentIdsForOrders[orderItem.orderId], - shipmentPackages: shipmentPackagesByOrder[orderItem.orderId], + shipmentIds: shipmentIdsForOrders[`${orderItem.orderId}_${orderItem.picklistBinId}`], + shipmentPackages: shipmentPackagesByOrder[`${orderItem.orderId}_${orderItem.picklistBinId}`], carrierPartyIds, shipmentBoxTypeByCarrierParty: carrierPartyIds.reduce((shipmentBoxType: any, carrierPartyId: any) => { if(shipmentBoxType[carrierPartyId]) { diff --git a/src/views/InProgress.vue b/src/views/InProgress.vue index c94b8409..230c34e2 100644 --- a/src/views/InProgress.vue +++ b/src/views/InProgress.vue @@ -662,7 +662,7 @@ export default defineComponent({ }, async fetchShipmentRouteSegmentInformation(shipmentIds: Array) { const payload = { - "inpurFields": { + "inputFields": { "carrierPartyId": "_NA_", "carrierPartyId_op": "notEqual", "shipmentId": shipmentIds, From bbd5115237ae0dc414cac23d3d869ac02342a563 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Thu, 13 Jul 2023 15:11:54 +0530 Subject: [PATCH 2/3] Added: some comments in the code(#155) --- src/services/UtilService.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/services/UtilService.ts b/src/services/UtilService.ts index dc67ac62..41b9276a 100644 --- a/src/services/UtilService.ts +++ b/src/services/UtilService.ts @@ -47,6 +47,7 @@ const findShipmentIdsForOrders = async(picklistBinIds: Array, orderIds: if (!hasError(resp)) { shipmentIdsForOrders = resp?.data.docs.reduce((shipmentIdsForOrders: any, shipment: any) => { + // creating key in this pattern as the same order can have multiple picklist bin and in that we need to find to which picklist bin shipment is associated const key = `${shipment.primaryOrderId}_${shipment.picklistBinId}` if(shipmentIdsForOrders[key]) { shipmentIdsForOrders[key].push(shipment.shipmentId) @@ -89,6 +90,7 @@ const findShipmentPackages = async(shipmentIds: Array): Promise => if(resp?.status == 200 && !hasError(resp) && resp.data.count) { shipmentPackages = resp.data.docs.reduce((shipmentForOrders: any, shipmentPackage: any) => { + // creating key in this pattern as the same order can have multiple picklist bin and in that we need to find to which picklist bin shipment is associated const key = `${shipmentPackage.primaryOrderId}_${shipmentPackage.picklistBinId}` if(shipmentForOrders[key]) { shipmentForOrders[key].push(shipmentPackage) From fa7d81700b1a35d0bd00333a84e4c8267f41014f Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Thu, 13 Jul 2023 15:30:46 +0530 Subject: [PATCH 3/3] Improved: variable names as per the changes in the object information(#155) --- src/store/modules/order/actions.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/store/modules/order/actions.ts b/src/store/modules/order/actions.ts index 7dea149d..83865e06 100644 --- a/src/store/modules/order/actions.ts +++ b/src/store/modules/order/actions.ts @@ -29,23 +29,23 @@ const actions: ActionTree = { try { // maintaining an object containing information of shipmentIds for each order - const shipmentIdsForOrders = await UtilService.findShipmentIdsForOrders(picklistBinIds, orderIds); + const shipmentIdsForOrderAndPicklistBin = await UtilService.findShipmentIdsForOrders(picklistBinIds, orderIds); - let shipmentPackagesByOrder = {} as any, itemInformationByOrder = {} as any, carrierPartyIdsByShipment = {} as any, carrierShipmentBoxType = {} as any + let shipmentPackagesByOrderAndPicklistBin = {} as any, itemInformationByOrder = {} as any, carrierPartyIdsByShipment = {} as any, carrierShipmentBoxType = {} as any // storing all the shipmentIds for all the orders in an array to use furthur - const orderShipmentIds = [...(new Set(Object.values(shipmentIdsForOrders).flat()))] as Array + const orderShipmentIds = [...(new Set(Object.values(shipmentIdsForOrderAndPicklistBin).flat()))] as Array // TODO: handle case when shipmentIds is empty // https://stackoverflow.com/questions/28066429/promise-all-order-of-resolved-values - const [shipmentPackagesByOrderInformation, itemInformationByOrderInformation, carrierPartyIdsByShipmentInformation] = await Promise.all([UtilService.findShipmentPackages(orderShipmentIds), UtilService.findShipmentItemInformation(orderShipmentIds), UtilService.findCarrierPartyIdsForShipment(orderShipmentIds)]) + const [shipmentPackagesByOrderInformationAndPicklistBin, itemInformationByOrderInformation, carrierPartyIdsByShipmentInformation] = await Promise.all([UtilService.findShipmentPackages(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())] - shipmentPackagesByOrder = { - ...shipmentPackagesByOrder, - ...shipmentPackagesByOrderInformation + shipmentPackagesByOrderAndPicklistBin = { + ...shipmentPackagesByOrderAndPicklistBin, + ...shipmentPackagesByOrderInformationAndPicklistBin } itemInformationByOrder = { @@ -66,7 +66,7 @@ const actions: ActionTree = { inProgressOrders = inProgressOrders.map((order: any) => { // if for an order shipment information is not available then returning the same order information again - if(!shipmentIdsForOrders[`${order.orderId}_${order.picklistBinId}`]) { + if(!shipmentIdsForOrderAndPicklistBin[`${order.orderId}_${order.picklistBinId}`]) { // if there are no shipment for the order, there is some issue with the order if (picklistBinIds.includes(order.picklistBinId) && orderIds.includes(order.orderId)) { return { @@ -86,7 +86,7 @@ const actions: ActionTree = { item.shipmentItemSeqId = shipment.shipmentItemSeqId } - item.selectedBox = shipmentPackagesByOrder[`${item.orderId}_${item.picklistBinId}`]?.find((shipmentPackage: any) => shipmentPackage.shipmentId === item.shipmentId)?.packageName + item.selectedBox = shipmentPackagesByOrderAndPicklistBin[`${item.orderId}_${item.picklistBinId}`]?.find((shipmentPackage: any) => shipmentPackage.shipmentId === item.shipmentId)?.packageName }) const orderItem = order.items[0]; @@ -94,8 +94,8 @@ const actions: ActionTree = { return { ...order, - shipmentIds: shipmentIdsForOrders[`${orderItem.orderId}_${orderItem.picklistBinId}`], - shipmentPackages: shipmentPackagesByOrder[`${orderItem.orderId}_${orderItem.picklistBinId}`], + shipmentIds: shipmentIdsForOrderAndPicklistBin[`${orderItem.orderId}_${orderItem.picklistBinId}`], + shipmentPackages: shipmentPackagesByOrderAndPicklistBin[`${orderItem.orderId}_${orderItem.picklistBinId}`], carrierPartyIds, shipmentBoxTypeByCarrierParty: carrierPartyIds.reduce((shipmentBoxType: any, carrierPartyId: any) => { if(shipmentBoxType[carrierPartyId]) {