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: avoiding refetching of item on adding new item #651

Merged
merged 2 commits into from
Jan 20, 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
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
Loading