Skip to content

Commit

Permalink
Merge pull request #651 from amansinghbais/refetch-issue
Browse files Browse the repository at this point in the history
Fixed: avoiding refetching of item on adding new item
  • Loading branch information
ravilodhi authored Jan 20, 2025
2 parents 5fbfd54 + 59befca commit 152bb39
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/store/modules/product/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const actions: ActionTree<ProductState, RootState> = {

async fetchProductByIdentification ( { commit, state }, payload) {
const cachedProductIds = Object.keys(state.cached);
if(cachedProductIds.includes(payload.scannedValue)) return;
if(cachedProductIds.includes(payload.scannedValue)) return state.cached[payload.scannedValue];
const productIdentifications = process.env.VUE_APP_PRDT_IDENT ? JSON.parse(JSON.stringify(process.env.VUE_APP_PRDT_IDENT)) : []

const productStoreSettings = store.getters["user/getProductStoreSettings"];
Expand Down
50 changes: 36 additions & 14 deletions src/views/HardCountDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -469,18 +469,29 @@ async function addProductToItemsList() {
initializeObserver()
}, 0);
}
findProductFromIdentifier(queryString.value.trim());
findProductFromIdentifier(queryString.value.trim(), newItem);
return newItem;
}
async function findProductFromIdentifier(scannedValue: string ) {
async function findProductFromIdentifier(scannedValue: string, newItem: any ) {
const product = await store.dispatch("product/fetchProductByIdentification", { scannedValue })
let newItem = {} as any;
if(product?.productId) newItem = await addProductToCount(product.productId)
setTimeout(() => {
updateCurrentItemInList(newItem, scannedValue);
}, 1000)
if(productStoreSettings.value['showQoh']) {
let updatedItem = {} as any;
if(product?.productId) updatedItem = await addProductToCount(product.productId)
setTimeout(() => {
updateCurrentItemInList(updatedItem, scannedValue);
}, 1000)
} else {
let importItemSeqId = "" as any;
if(product?.productId) importItemSeqId = await addProductToCount(product.productId)
setTimeout(() => {
updateCurrentItemInList({...newItem, importItemSeqId, ...product}, scannedValue);
}, 1000)
}
}
async function addProductToCount(productId: any) {
Expand All @@ -501,19 +512,25 @@ async function addProductToCount(productId: any) {
if(!hasError(resp) && resp.data?.itemList?.length) {
const importItemSeqId = resp.data.itemList[0].importItemSeqId
resp = await CountService.fetchCycleCountItems({ inventoryCountImportId: cycleCount.value.inventoryCountImportId, importItemSeqId, pageSize: 1 })
if(!hasError(resp)) {
newProduct = resp.data.itemList[0];
if(productStoreSettings.value['showQoh']) {
resp = await CountService.fetchCycleCountItems({ inventoryCountImportId: cycleCount.value.inventoryCountImportId, importItemSeqId, pageSize: 1 })
if(!hasError(resp)) {
newProduct = resp.data.itemList[0];
return newProduct
} else {
throw resp;
}
} else {
throw resp;
return importItemSeqId
}
} else {
throw resp;
}
} catch(err) {
logger.error("Failed to add product to count", err)
}
return newProduct;
return "";
}
async function updateCurrentItemInList(newItem: any, scannedValue: string) {
Expand Down Expand Up @@ -700,8 +717,13 @@ async function matchProduct(currentProduct: any) {
addProductModal.onDidDismiss().then(async (result) => {
if(result.data?.selectedProduct) {
const product = result.data.selectedProduct
const newItem = await addProductToCount(product.productId)
await updateCurrentItemInList(newItem, currentProduct.scannedId);
if(productStoreSettings.value['showQoh']) {
const newItem = await addProductToCount(product.productId)
await updateCurrentItemInList(newItem, currentProduct.scannedId);
} else {
const importItemSeqId = await addProductToCount(product.productId)
await updateCurrentItemInList({ ...currentProduct, ...product, importItemSeqId }, currentProduct.scannedId);
}
}
})
Expand Down

0 comments on commit 152bb39

Please sign in to comment.