Skip to content
Open
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
20 changes: 18 additions & 2 deletions src/views/HardCountDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ const isAnimationInProgress = ref(false);
const productInAnimation = ref({}) as any;
const isLoadingItems = ref(true);
const scannedItem = ref({}) as any;
let scannedItemsQueue = {} as any;

onIonViewDidEnter(async() => {
await store.dispatch('count/setCountDetailPageActive', true);
Expand Down Expand Up @@ -531,7 +532,7 @@ async function addProductToItemsList() {
initializeObserver()
}, 0);
}
findProductFromIdentifier(queryString.value.trim(), newItem);
findProductFromIdentifier(queryString.value.trim(), JSON.parse(JSON.stringify(newItem)));
return newItem;
}

Expand Down Expand Up @@ -595,6 +596,13 @@ async function addProductToCount(productId: any) {
return "";
}

// Synchronizes a scanned item with an object, removing it from the scanned items queue.
function syncScannedItem(updatedItem: any) {
const scannedId = updatedItem.scannedId;
if(!scannedId) return updatedItem;
delete scannedItemsQueue[scannedId];
Comment on lines +601 to +603

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This function can be simplified for better clarity and to address the inconsistent return value. It currently returns updatedItem in one branch but implicitly undefined in another. Since the return value is not used, it's best to have no return value for consistency and to signal that the function's purpose is its side effect.

  if (updatedItem?.scannedId) {
    delete scannedItemsQueue[updatedItem.scannedId];
  }

}

async function updateCurrentItemInList(newItem: any, scannedValue: string) {
const items = JSON.parse(JSON.stringify(cycleCountItems.value.itemList));
const updatedProduct = JSON.parse(JSON.stringify(currentProduct.value))
Expand All @@ -609,7 +617,11 @@ async function updateCurrentItemInList(newItem: any, scannedValue: string) {
} else if(selectedSegment.value === "unmatched" && (inputCount.value || updatedItem.scannedCount)) {
newCount = Number(inputCount.value || 0) + Number(updatedItem.scannedCount || 0)
}


if(scannedItemsQueue[updatedItem.scannedId]) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This condition if(scannedItemsQueue[updatedItem.scannedId]) will evaluate to false if the queued count is 0. Since 0 is a valid quantity, this check could cause the count to be ignored, potentially leading to the very issue of items being stuck in a pending state that this PR aims to fix. You should check for the property's existence instead of its truthiness.

  if(updatedItem.scannedId in scannedItemsQueue) {

newCount = scannedItemsQueue[updatedItem.scannedId]
}

if(newCount && updatedItem?.importItemSeqId && updatedItem.productId) {
try {
const resp = await CountService.updateCount({
Expand All @@ -630,6 +642,8 @@ async function updateCurrentItemInList(newItem: any, scannedValue: string) {
}
}

syncScannedItem(updatedItem);

if(updatedProduct.scannedId === updatedItem.scannedId) {
store.dispatch("product/currentProduct", updatedItem);
}
Expand Down Expand Up @@ -752,6 +766,8 @@ async function saveCount(currentProduct: any, isScrollEvent = false) {
if(selectedCountUpdateType.value === "replace") item.scannedCount = currentCount
else item.scannedCount = Number(currentCount) + Number(prevCount)
currentItem = item;
// Updates the quantity of a scanned item in the scanned items queue.
scannedItemsQueue[currentProduct.scannedId] = item.scannedCount;
}
})
await store.dispatch('count/updateCycleCountItems', items);
Expand Down
Loading