Skip to content

Commit

Permalink
Merge pull request #603 from amansinghbais/#602
Browse files Browse the repository at this point in the history
Implemented: sorting on the cycle count items based on the parentProductName (#602)
  • Loading branch information
ymaheshwari1 authored Jan 14, 2025
2 parents 7c809e3 + bc70509 commit a22fefa
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/store/modules/count/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import RootState from "@/store/RootState"
import CountState from "./CountState"
import * as types from "./mutation-types"
import { CountService } from "@/services/CountService"
import { hasError, showToast } from "@/utils"
import { hasError, showToast, sortListByField } from "@/utils"
import { translate } from "@/i18n"
import router from "@/router"
import logger from "@/logger";
Expand Down Expand Up @@ -196,6 +196,9 @@ const actions: ActionTree<CountState, RootState> = {
} catch(err: any) {
logger.error(err)
}

if(payload.isSortingRequired) items = sortListByField(items, "parentProductName");

this.dispatch("product/fetchProducts", { productIds: [...new Set(items.map((item: any) => item.productId))] })
if(cachedProducts?.length) items = items.concat(cachedProducts)
commit(types.COUNT_ITEMS_UPDATED, { itemList: items })
Expand Down
12 changes: 11 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,14 @@ const downloadCsv = (csv: any, fileName: any) => {
return blob;
};

export { downloadCsv, jsonToCsv, showToast, hasError, handleDateTimeInput, getCycleCountStats, getDateTime, getDateWithOrdinalSuffix, getDerivedStatusForCount, getFacilityName, getPartyName, getProductIdentificationValue, timeFromNow, parseCsv }
function sortListByField(list: any, field = "parentProductName") {
return list.sort((a: any, b: any) => {
if (!a[field] && b[field]) return 1; // If 'item1' has no field, it goes after 'item2'
if (a[field] && !b[field]) return -1; // If 'item2' has no field, it goes after 'item1'
if (a[field] < b[field]) return -1; // Normal alphabetical sorting
if (a[field] > b[field]) return 1; // Normal alphabetical sorting
return 0; // If fields are equal
});
}

export { downloadCsv, jsonToCsv, showToast, hasError, handleDateTimeInput, getCycleCountStats, getDateTime, getDateWithOrdinalSuffix, getDerivedStatusForCount, getFacilityName, getPartyName, getProductIdentificationValue, timeFromNow, parseCsv, sortListByField }
4 changes: 3 additions & 1 deletion src/views/AssignedDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ import AssignedCountPopover from "@/components/AssignedCountPopover.vue"
import store from "@/store"
import logger from "@/logger"
import { CountService } from "@/services/CountService"
import { hasError, showToast, getDateWithOrdinalSuffix, getDateTime, getFacilityName, getPartyName, getProductIdentificationValue } from "@/utils"
import { hasError, showToast, getDateWithOrdinalSuffix, getDateTime, getFacilityName, getPartyName, getProductIdentificationValue, sortListByField } from "@/utils"
import emitter from '@/event-bus';
import AddProductModal from "@/components/AddProductModal.vue"
import router from "@/router";
Expand Down Expand Up @@ -241,6 +241,8 @@ async function fetchCountItems() {
logger.error(err)
}
items = sortListByField(items, "parentProductName");
currentCycleCount.value["items"] = items
store.dispatch("product/fetchProducts", { productIds: [...new Set(items.map((item: any) => item.productId))] })
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/CountDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ let isScanningInProgress = ref(false);
onIonViewDidEnter(async() => {
emitter.emit("presentLoader");
await Promise.allSettled([await fetchCycleCount(), store.dispatch("count/fetchCycleCountItems", { inventoryCountImportId : props?.id })])
await Promise.allSettled([await fetchCycleCount(), store.dispatch("count/fetchCycleCountItems", { inventoryCountImportId : props?.id, isSortingRequired: true })])
selectedSegment.value = 'all';
queryString.value = '';
previousItem = itemsList.value[0]
Expand Down
4 changes: 3 additions & 1 deletion src/views/DraftDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ import { calendarNumberOutline, checkmarkCircle, businessOutline, addCircleOutli
import { IonBackButton, IonButton, IonChip, IonContent, IonDatetime, IonFab, IonFabButton, IonHeader, IonIcon, IonInput, IonItem, IonLabel, IonList, IonModal, IonPage, IonSpinner, IonThumbnail, IonTitle, IonToolbar, modalController, onIonViewDidEnter, onIonViewWillEnter} from "@ionic/vue";
import { CountService } from "@/services/CountService"
import { defineProps, ref, nextTick, computed, watch } from "vue"
import { hasError, getDateTime, getDateWithOrdinalSuffix, handleDateTimeInput, getFacilityName, getProductIdentificationValue, showToast, parseCsv } from "@/utils";
import { hasError, getDateTime, getDateWithOrdinalSuffix, handleDateTimeInput, getFacilityName, getProductIdentificationValue, showToast, parseCsv, sortListByField } from "@/utils";
import emitter from "@/event-bus"
import logger from "@/logger"
import { DateTime } from "luxon"
Expand Down Expand Up @@ -285,6 +285,8 @@ async function fetchCountItems() {
logger.error(err)
}
items = sortListByField(items, "parentProductName");
currentCycleCount.value["items"] = items
store.dispatch("product/fetchProducts", { productIds: [...new Set(items.map((item: any) => item.productId))] })
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/HardCountDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ let isScanningInProgress = ref(false);
onIonViewDidEnter(async() => {
emitter.emit("presentLoader");
await Promise.allSettled([fetchCycleCount(), await store.dispatch("count/fetchCycleCountItems", { inventoryCountImportId : props?.id })])
await Promise.allSettled([fetchCycleCount(), await store.dispatch("count/fetchCycleCountItems", { inventoryCountImportId : props?.id, isSortingRequired: false })])
previousItem = itemsList.value[0];
await store.dispatch("product/currentProduct", itemsList.value?.length ? itemsList.value[0] : {})
barcodeInputRef.value?.$el?.setFocus();
Expand Down
4 changes: 3 additions & 1 deletion src/views/PendingReviewDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ import { computed, defineProps, nextTick, ref } from "vue";
import store from "@/store"
import { CountService } from "@/services/CountService"
import emitter from '@/event-bus';
import { showToast, getDateWithOrdinalSuffix, hasError, getFacilityName, getPartyName, timeFromNow, getProductIdentificationValue, getDateTime } from "@/utils"
import { showToast, getDateWithOrdinalSuffix, hasError, getFacilityName, getPartyName, timeFromNow, getProductIdentificationValue, getDateTime, sortListByField } from "@/utils"
import logger from "@/logger";
import AddProductModal from "@/components/AddProductModal.vue";
import router from "@/router";
Expand Down Expand Up @@ -284,6 +284,8 @@ async function fetchCountItems() {
logger.error(err)
}
items = sortListByField(items, "parentProductName");
currentCycleCount.value["items"] = items.map((item: any) => ({ ...item, isChecked: false }))
store.dispatch("product/fetchProducts", { productIds: [...new Set(items.map((item: any) => item.productId))] })
}
Expand Down

0 comments on commit a22fefa

Please sign in to comment.