Skip to content

Commit

Permalink
Improved: updated the logic when product does not found in the cached…
Browse files Browse the repository at this point in the history
…Product & need to fetch from api(#429)

- Removed the toast and fixed the case when the SKU isn't scanned properly.
- Update the variable name.
  • Loading branch information
R-Sourabh committed Nov 6, 2024
1 parent bc9e99c commit 377b91f
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions src/views/CountDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,6 @@
</ion-list>
<ion-list v-else-if="product.quantity >= 0">
<template v-if="productStoreSettings['forceScan']">
<ion-item lines="none">
<ion-label>
{{ translate('Force scan enabled') }}
<p>{{ translate("Scan the barcode on each unit to increment the counted inventory") }}</p>
</ion-label>
</ion-item>
</template>
<ion-item>
{{ translate("Counted") }}
<ion-label slot="end">{{ product.quantity }}</ion-label>
Expand Down Expand Up @@ -209,7 +201,7 @@
</ion-item>
<ion-item>
<ion-label>{{ translate("Count") }}</ion-label>
<ion-label slot="end">{{ productStoreSettings['forceScan'] && inputCount === '' ? 0 : inputCount }}</ion-label>
<ion-label slot="end">{{ inputCount === '' ? 0 : inputCount }}</ion-label>
</ion-item>
</template>
Expand Down Expand Up @@ -361,18 +353,24 @@ function handleBlur() {
async function handleInput(event) {
if (!isInputFocused.value) return;
let sku = event.target.value;
const cachedProducts = getCachedProducts.value;
let scannedItem;
if(!sku) {
showToast(translate("Scan a valid product sku"));
return;
}
scannedItem = Object.keys(cachedProducts).find(productId => cachedProducts[productId].sku === sku);
if (!scannedItem) {
scannedItem = await findProduct(sku);
const cachedProducts = getCachedProducts.value;
let scannedItemId = Object.keys(cachedProducts).find(productId => cachedProducts[productId].sku === sku);
if (!scannedItemId) {
const product = await findProduct(sku);
if(product) {
scannedItemId = product.data.response?.docs[0]?.productId
}
}
if (scannedItem) {
if (scannedItem === product.value.productId) {
if (scannedItemId) {
if (scannedItemId === product.value.productId) {
inputCount.value++;
scannedCount.value = ''
} else {
showToast(translate('Scanned item does not match current product'));
}
Expand Down Expand Up @@ -651,10 +649,8 @@ async function readyForReview() {
}
async function findProduct(sku) {
if(!sku) {
showToast(translate("Scan a valid product sku"));
return;
}
if(!sku) return;
let resp;
const viewSize = 1, viewIndex = 0;
Expand Down

0 comments on commit 377b91f

Please sign in to comment.