From e40e62ab218c3beb85fbada4fdbe5c68fbbc2b48 Mon Sep 17 00:00:00 2001 From: R-Sourabh Date: Fri, 6 Dec 2024 12:45:47 +0530 Subject: [PATCH 1/3] Improved: added support to fetch the updated inventory in the completed tab(#468) --- src/views/Orders.vue | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/views/Orders.vue b/src/views/Orders.vue index 710a5ea0..991f5462 100644 --- a/src/views/Orders.vue +++ b/src/views/Orders.vue @@ -257,7 +257,8 @@ export default defineComponent({ isCompletedOrdersScrollable: 'order/isCompletedOrdersScrollable', notifications: 'user/getNotifications', unreadNotificationsStatus: 'user/getUnreadNotificationsStatus', - getBopisProductStoreSettings: 'user/getBopisProductStoreSettings' + getBopisProductStoreSettings: 'user/getBopisProductStoreSettings', + getProductStock: 'stock/getProductStock', }) }, data() { @@ -434,9 +435,22 @@ export default defineComponent({ }, async deliverShipment (order: any) { await this.store.dispatch('order/deliverShipment', order) - .then((resp) => { + .then(async (resp) => { if(!hasError(resp)){ showToast(translate('Order delivered to', {customerName: order.customer.name})) + + const productIds = [...new Set(order.parts.reduce((productId: any, part: any) => { + const ids = part.items.map((item: any) => item.productId) + return productId.concat(ids) + }, []))] + + const fetchProductStock = productIds.map(async (productId: any) => { + const productStock = this.getProductStock(productId); + if (productStock && productStock.quantityOnHandTotal >= 0) { + return this.store.dispatch('stock/fetchStock', { productId }) + } + }) + await Promise.allSettled(fetchProductStock); } }) }, From 2dd65ec9b851730ad8dc95a9d6ec2dff364ed8eb Mon Sep 17 00:00:00 2001 From: R-Sourabh Date: Mon, 9 Dec 2024 18:34:24 +0530 Subject: [PATCH 2/3] Improved: Refactor deliverShipment method to remove async/await and promise logic(#468) --- src/views/Orders.vue | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/views/Orders.vue b/src/views/Orders.vue index 991f5462..9c8c0d14 100644 --- a/src/views/Orders.vue +++ b/src/views/Orders.vue @@ -435,8 +435,8 @@ export default defineComponent({ }, async deliverShipment (order: any) { await this.store.dispatch('order/deliverShipment', order) - .then(async (resp) => { - if(!hasError(resp)){ + .then((resp) => { + if(!hasError(resp)) { showToast(translate('Order delivered to', {customerName: order.customer.name})) const productIds = [...new Set(order.parts.reduce((productId: any, part: any) => { @@ -444,13 +444,12 @@ export default defineComponent({ return productId.concat(ids) }, []))] - const fetchProductStock = productIds.map(async (productId: any) => { + productIds.map((productId: any) => { const productStock = this.getProductStock(productId); if (productStock && productStock.quantityOnHandTotal >= 0) { - return this.store.dispatch('stock/fetchStock', { productId }) + this.store.dispatch('stock/fetchStock', { productId }); } }) - await Promise.allSettled(fetchProductStock); } }) }, From de5033c6862d973bb46d734b1fb5f3b81c1285d9 Mon Sep 17 00:00:00 2001 From: R-Sourabh Date: Tue, 10 Dec 2024 11:49:51 +0530 Subject: [PATCH 3/3] Improved: Added a comment explaining the logic for fetching the updated inventory of the order item (#468) --- src/views/Orders.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/views/Orders.vue b/src/views/Orders.vue index 9c8c0d14..7f0eb1c4 100644 --- a/src/views/Orders.vue +++ b/src/views/Orders.vue @@ -439,6 +439,8 @@ export default defineComponent({ if(!hasError(resp)) { showToast(translate('Order delivered to', {customerName: order.customer.name})) + // We are collecting the product IDs of the order items and then fetching stock information + // for each product ID if it is available for updated inventory. const productIds = [...new Set(order.parts.reduce((productId: any, part: any) => { const ids = part.items.map((item: any) => item.productId) return productId.concat(ids)