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

Fixed: match product modal not updating the item data in the state (#528) #544

Merged
merged 2 commits into from
Dec 23, 2024
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
7 changes: 6 additions & 1 deletion src/components/MatchProductModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;

async function handleSearch() {
if(!queryString.value.trim()) {
isSearching.value = false;
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions src/store/modules/product/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ const actions: ActionTree<ProductState, RootState> = {
return {};
},

async addProductToCached({ commit }, payload) {
commit(types.PRODUCT_ADD_TO_CACHED, payload);
},

async clearProducts({ commit }) {
commit(types.PRODUCT_LIST_UPDATED, { products: [], total: 0 });
},
Expand Down
6 changes: 2 additions & 4 deletions src/store/modules/product/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ const mutations: MutationTree <ProductState> = {
}
},
[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) {
Expand Down
21 changes: 15 additions & 6 deletions src/views/HardCountDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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)
Expand All @@ -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"]
}
}
})

Expand Down Expand Up @@ -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);
}
})

Expand Down
Loading