Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: sorting on the cycle count items based on the parentProductName (#602) #603

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 @@
} 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 All @@ -209,7 +212,7 @@
commit(types.COUNT_ITEMS_UPDATED, [])
},

async fetchCycleCountImportSystemMessages({commit} ,payload) {

Check warning on line 215 in src/store/modules/count/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'payload' is defined but never used

Check warning on line 215 in src/store/modules/count/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'payload' is defined but never used
let systemMessages;
try {
const twentyFourHoursEarlier = DateTime.now().minus({ hours: 24 });
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
Loading