diff --git a/src/components/MatchProductModal.vue b/src/components/MatchProductModal.vue index 74d0f65e..779620c2 100644 --- a/src/components/MatchProductModal.vue +++ b/src/components/MatchProductModal.vue @@ -72,13 +72,16 @@ import { getProductIdentificationValue, hasError } from "@/utils" import Image from "@/components/Image.vue" import { ProductService } from "@/services/ProductService"; import logger from "@/logger"; + const props = defineProps(["items"]) const productStoreSettings = computed(() => store.getters["user/getProductStoreSettings"]) const getProduct = computed(() => (id: any) => store.getters["product/getProduct"](id)) + const products = ref([]) as any; let queryString = ref(''); const isSearching = ref(false); const selectedProductId = ref("") as Ref; + async function handleSearch() { if(!queryString.value.trim()) { isSearching.value = false; @@ -106,7 +109,9 @@ function closeModal(payload = {}) { modalController.dismiss({ dismissed: true, ...payload }); } function save() { - closeModal({ selectedProduct: products.value.find((product: any) => product.productId === selectedProductId) }) + const selectedProduct = products.value.find((product: any) => product.productId === selectedProductId.value) + store.dispatch("product/addProductToCached", selectedProduct); + closeModal({ selectedProduct }) } function isProductAvailableInCycleCount(id: string) { return props.items.some((item: any) => item.productId === id && item.itemStatusId !== "INV_COUNT_REJECTED") diff --git a/src/store/modules/product/actions.ts b/src/store/modules/product/actions.ts index 993b98ba..09e00ea6 100644 --- a/src/store/modules/product/actions.ts +++ b/src/store/modules/product/actions.ts @@ -94,6 +94,10 @@ const actions: ActionTree = { return {}; }, + async addProductToCached({ commit }, payload) { + commit(types.PRODUCT_ADD_TO_CACHED, payload); + }, + async clearProducts({ commit }) { commit(types.PRODUCT_LIST_UPDATED, { products: [], total: 0 }); }, diff --git a/src/store/modules/product/mutations.ts b/src/store/modules/product/mutations.ts index d2f07837..7bab4bbc 100644 --- a/src/store/modules/product/mutations.ts +++ b/src/store/modules/product/mutations.ts @@ -11,10 +11,8 @@ const mutations: MutationTree = { } }, [types.PRODUCT_ADD_TO_CACHED] (state, payload) { - if (payload.products) { - payload.products.forEach((product: any) => { - state.cached[product.productId] = product - }); + if(payload.productId) { + state.cached[payload.productId] = payload } }, [types.PRODUCT_CURRENT_UPDATED] (state, payload) { diff --git a/src/views/HardCountDetail.vue b/src/views/HardCountDetail.vue index 9bf446bc..80a1f849 100644 --- a/src/views/HardCountDetail.vue +++ b/src/views/HardCountDetail.vue @@ -393,7 +393,8 @@ async function addProductToItemsList() { scannedId: queryString.value, isMatching: true, itemStatusId: "INV_COUNT_CREATED", - statusId: "INV_COUNT_ASSIGNED" + statusId: "INV_COUNT_ASSIGNED", + inventoryCountImportId: cycleCount.value.inventoryCountImportId } const items = JSON.parse(JSON.stringify(cycleCountItems.value.itemList)) @@ -432,12 +433,12 @@ async function addProductToCount(productId: any) { return 0; } -async function updateCurrentItemInList(importItemSeqId: any, product: any, scannedValue: string) { +async function updateCurrentItemInList(importItemSeqId: any, product: any, scannedValue: string, isMatchedUpdate = false) { const items = JSON.parse(JSON.stringify(cycleCountItems.value.itemList)); const updatedProduct = JSON.parse(JSON.stringify(currentProduct.value)) let prevItem = {} as any, hasErrorSavingCount = false; - if(updatedProduct.scannedId === scannedValue) { + if(updatedProduct.scannedId === scannedValue && !isMatchedUpdate) { if(importItemSeqId) { updatedProduct["importItemSeqId"] = importItemSeqId updatedProduct["productId"] = product.productId @@ -447,7 +448,7 @@ async function updateCurrentItemInList(importItemSeqId: any, product: any, scann } updatedProduct["isMatching"] = false; store.dispatch("product/currentProduct", updatedProduct); - } else if(importItemSeqId) { + } else if(importItemSeqId && isMatchedUpdate) { prevItem = items.find((item: any) => item.scannedId === scannedValue); if(prevItem && prevItem?.scannedCount >= 0) { @@ -462,6 +463,11 @@ async function updateCurrentItemInList(importItemSeqId: any, product: any, scann if(hasError(resp)) { hasErrorSavingCount = true; + updatedProduct["isMatching"] = false; + updatedProduct["isMatchNotFound"] = false + updatedProduct["importItemSeqId"] = importItemSeqId + updatedProduct["productId"] = product.productId + updatedProduct["productId"] = updatedProduct.scannedCount } } catch(error) { logger.error(error) @@ -479,7 +485,10 @@ async function updateCurrentItemInList(importItemSeqId: any, product: any, scann item["isMatchNotFound"] = true } item["isMatching"] = false; - if(prevItem && Object.keys(prevItem)?.length && !hasErrorSavingCount) delete item["scannedCount"] + if(prevItem && Object.keys(prevItem)?.length && !hasErrorSavingCount) { + item["quantity"] = item.scannedCount + delete item["scannedCount"] + } } }) @@ -622,7 +631,7 @@ async function matchProduct(currentProduct: any) { if(result.data.selectedProduct) { const product = result.data.selectedProduct const importItemSeqId = await addProductToCount(product.productId) - updateCurrentItemInList(importItemSeqId, product.productId, currentProduct.scannedId); + updateCurrentItemInList(importItemSeqId, product, currentProduct.scannedId, true); } })