Skip to content

Commit

Permalink
Merge pull request #193 from ymaheshwari1/fulfillment/#155
Browse files Browse the repository at this point in the history
Fixed: issue of shipmentId not found on items, and improved logic to create unique key when fetching shipment and shipment route information(#155)
  • Loading branch information
adityasharma7 authored Jul 13, 2023
2 parents 9bd1af2 + fa7d817 commit 282bf41
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
20 changes: 12 additions & 8 deletions src/services/UtilService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const findShipmentIdsForOrders = async(picklistBinIds: Array<string>, orderIds:
"statusId": statusId,
"statusId_op": "in"
},
"fieldList": ["shipmentId", "primaryOrderId"],
"fieldList": ["shipmentId", "primaryOrderId", "picklistBinId"],
"viewSize": 200, // maximum records we have for orders
"distinct": "Y"
}
Expand All @@ -47,10 +47,12 @@ const findShipmentIdsForOrders = async(picklistBinIds: Array<string>, orderIds:

if (!hasError(resp)) {
shipmentIdsForOrders = resp?.data.docs.reduce((shipmentIdsForOrders: any, shipment: any) => {
if(shipmentIdsForOrders[shipment.primaryOrderId]) {
shipmentIdsForOrders[shipment.primaryOrderId].push(shipment.shipmentId)
// 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)
} else {
shipmentIdsForOrders[shipment.primaryOrderId] = [shipment.shipmentId]
shipmentIdsForOrders[key] = [shipment.shipmentId]
}
return shipmentIdsForOrders
}, {})
Expand All @@ -74,7 +76,7 @@ const findShipmentPackages = async(shipmentIds: Array<string>): Promise<any> =>
"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"
}
Expand All @@ -88,10 +90,12 @@ const findShipmentPackages = async(shipmentIds: Array<string>): Promise<any> =>

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)
// 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)
} else {
shipmentForOrders[shipmentPackage.primaryOrderId] = [shipmentPackage]
shipmentForOrders[key] = [shipmentPackage]
}
return shipmentForOrders
}, {})
Expand Down
30 changes: 18 additions & 12 deletions src/store/modules/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ const actions: ActionTree<OrderState, RootState> = {

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<string>
const orderShipmentIds = [...(new Set(Object.values(shipmentIdsForOrderAndPicklistBin).flat()))] as Array<string>

// 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 = {
Expand All @@ -66,7 +66,7 @@ const actions: ActionTree<OrderState, RootState> = {
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(!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 {
Expand All @@ -79,17 +79,23 @@ const actions: ActionTree<OrderState, RootState> = {

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 = shipmentPackagesByOrderAndPicklistBin[`${item.orderId}_${item.picklistBinId}`]?.find((shipmentPackage: any) => shipmentPackage.shipmentId === item.shipmentId)?.packageName
})

const orderItem = order.items[0];
const carrierPartyIds = [...new Set(orderShipmentIds.map((id: any) => carrierPartyIdsByShipment[id]?.map((carrierParty: any) => carrierParty.carrierPartyId)).flat())]

return {
...order,
shipmentIds: shipmentIdsForOrders[orderItem.orderId],
shipmentPackages: shipmentPackagesByOrder[orderItem.orderId],
shipmentIds: shipmentIdsForOrderAndPicklistBin[`${orderItem.orderId}_${orderItem.picklistBinId}`],
shipmentPackages: shipmentPackagesByOrderAndPicklistBin[`${orderItem.orderId}_${orderItem.picklistBinId}`],
carrierPartyIds,
shipmentBoxTypeByCarrierParty: carrierPartyIds.reduce((shipmentBoxType: any, carrierPartyId: any) => {
if(shipmentBoxType[carrierPartyId]) {
Expand Down
2 changes: 1 addition & 1 deletion src/views/InProgress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ export default defineComponent({
},
async fetchShipmentRouteSegmentInformation(shipmentIds: Array<string>) {
const payload = {
"inpurFields": {
"inputFields": {
"carrierPartyId": "_NA_",
"carrierPartyId_op": "notEqual",
"shipmentId": shipmentIds,
Expand Down

0 comments on commit 282bf41

Please sign in to comment.