From c24208ee7060e2c4e0e8865343ff7f2fda3d815c Mon Sep 17 00:00:00 2001 From: Cybrosys Technologies Date: Mon, 23 Jun 2025 20:14:19 +0530 Subject: [PATCH] Jun 23: [FIX] Bug Fixed 'pos_restrict_product_stock' --- pos_restrict_product_stock/__manifest__.py | 2 +- .../doc/RELEASE_NOTES.md | 8 +- .../static/description/index.html | 2 +- .../static/src/js/OrderScreen.js | 75 ++++++++++++------- .../static/src/js/ProductScreen.js | 42 ++++++++--- .../static/src/js/RestrictStockPopup.js | 17 +++-- .../static/src/xml/RestrictStockPopup.xml | 2 +- 7 files changed, 92 insertions(+), 56 deletions(-) diff --git a/pos_restrict_product_stock/__manifest__.py b/pos_restrict_product_stock/__manifest__.py index 41270feee..8607e5c2e 100644 --- a/pos_restrict_product_stock/__manifest__.py +++ b/pos_restrict_product_stock/__manifest__.py @@ -20,7 +20,7 @@ ############################################################################# { 'name': 'Display Stock in POS | Restrict Out-of-Stock Products in POS', - 'version': '17.0.2.1.2', + 'version': '17.0.2.1.1', 'category': 'Point of Sale', 'summary': """Enhance your Point of Sale experience by preventing the ordering of out-of-stock products during your session""", diff --git a/pos_restrict_product_stock/doc/RELEASE_NOTES.md b/pos_restrict_product_stock/doc/RELEASE_NOTES.md index 78fa2666b..b1f1b001e 100644 --- a/pos_restrict_product_stock/doc/RELEASE_NOTES.md +++ b/pos_restrict_product_stock/doc/RELEASE_NOTES.md @@ -9,10 +9,4 @@ #### Version 17.0.2.1.1 #### Update - Added a new feature that restricts stock availability when clicking the payment button. -This will help prevent the ordering of out-of-stock products, whether entered via barcode or through any other method. - - -#### 12.06.2025 -#### Version 17.0.2.1.2 -#### Update -- Fixed the issue occurring while ordering out-of-stock products \ No newline at end of file +This will help prevent the ordering of out-of-stock products, whether entered via barcode or through any other method. \ No newline at end of file diff --git a/pos_restrict_product_stock/static/description/index.html b/pos_restrict_product_stock/static/description/index.html index 4831a74b3..a0238b27c 100644 --- a/pos_restrict_product_stock/static/description/index.html +++ b/pos_restrict_product_stock/static/description/index.html @@ -358,7 +358,7 @@ style="font-weight: 500;background-color: #fff; border-radius: 4px; padding: 1rem; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);">
Version - 17.0.2.1.2|Released on:28th November 2023
diff --git a/pos_restrict_product_stock/static/src/js/OrderScreen.js b/pos_restrict_product_stock/static/src/js/OrderScreen.js index f1da183ae..3e4d20422 100644 --- a/pos_restrict_product_stock/static/src/js/OrderScreen.js +++ b/pos_restrict_product_stock/static/src/js/OrderScreen.js @@ -1,4 +1,4 @@ -/** @odoo-module */ + /** @odoo-module */ import { Order } from "@point_of_sale/app/store/models"; import { patch } from "@web/core/utils/patch"; @@ -6,30 +6,51 @@ import RestrictStockPopup from "@pos_restrict_product_stock/js/RestrictStockPopu patch(Order.prototype, { async pay() { - var type = this.pos.config.stock_type - const pay = true - const body = [] - const pro_id = false - for (const line of this.orderlines) { - if (line.pos.config.is_restrict_product && ((type == 'qty_on_hand') && (line.product.qty_available <= 0)) | ((type == 'virtual_qty') && (line.product.virtual_available <= 0)) | - ((line.product.qty_available <= 0) && (line.product.virtual_available <= 0))) { - // If the product restriction is activated in the settings and quantity is out stock, it show the restrict popup. - body.push(line.product.display_name) - } - } - if (body.length > 0) { // Check if body has items - const confirmed = await this.pos.popup.add(RestrictStockPopup, { - body: body, - pro_id: pro_id - }); - if (confirmed == true) { - return super.pay(); // Proceed with payment - } else { - return ; - } - } else { - return super.pay(); // No restrictions, proceed with payment - } - } + const type = this.pos.config.stock_type; + const is_restrict = this.pos.config.is_restrict_product; + const body = []; + const productQuantities = {}; - }) \ No newline at end of file + for (const line of this.orderlines) { + const productId = line.product.id; + if (!productQuantities[productId]) { + productQuantities[productId] = { + name: line.product.display_name, + product: line.product, + total_qty: 0, + }; + } + productQuantities[productId].total_qty += line.quantity; + } + + for (const { product, total_qty, name } of Object.values(productQuantities)) { + if (is_restrict) { + const qty_available = product.qty_available; + const virtual_qty = product.virtual_available; + + const should_restrict = ( + (type === 'qty_on_hand' && total_qty > qty_available) || + (type === 'virtual_qty' && total_qty > virtual_qty) || + (total_qty > qty_available && total_qty > virtual_qty) + ); + + if (should_restrict) { + body.push(name); + } + } + } + if (body.length > 0) { + const confirmed = await this.pos.popup.add(RestrictStockPopup, { + body: body.join(', '), + pro_id: false + }); + + if (confirmed === true) { + return super.pay(); + } else { + return; + } + } + return super.pay(); + } +}) \ No newline at end of file diff --git a/pos_restrict_product_stock/static/src/js/ProductScreen.js b/pos_restrict_product_stock/static/src/js/ProductScreen.js index 7dbffcc27..55fe4e099 100644 --- a/pos_restrict_product_stock/static/src/js/ProductScreen.js +++ b/pos_restrict_product_stock/static/src/js/ProductScreen.js @@ -2,20 +2,40 @@ import { patch } from "@web/core/utils/patch"; import RestrictStockPopup from "@pos_restrict_product_stock/js/RestrictStockPopup" import { PosStore } from "@point_of_sale/app/store/pos_store"; +import { ErrorPopup } from "@point_of_sale/app/errors/popups/error_popup"; +import { _t } from "@web/core/l10n/translation"; patch(PosStore.prototype, { async addProductToCurrentOrder(...args) { - var type = this.config.stock_type - if (this.config.is_restrict_product && ((type == 'qty_on_hand') && (args['0'].qty_available <= 0)) | ((type == 'virtual_qty') && (args['0'].virtual_available <= 0)) | - ((args['0'].qty_available <= 0) && (args['0'].virtual_available <= 0))) { - // If the product restriction is activated in the settings and quantity is out stock, it show the restrict popup. - this.popup.add(RestrictStockPopup, { - body: args['0'].display_name, - pro_id: args['0'].id - }); + const product = args[0]; + const type = this.config.stock_type; + const order = this.get_order(); + const selected_orderline = order.get_selected_orderline(); + + let order_quantity = 1; + if (selected_orderline && selected_orderline.product.id === product.id) { + order_quantity = selected_orderline.quantity + 1; } - else{ - await super.addProductToCurrentOrder(...args) + + const qty_available = product.qty_available; + const virtual_qty = product.virtual_available; + + const should_restrict = + this.config.is_restrict_product && + ( + (type === 'qty_on_hand' && order_quantity > qty_available) || + (type === 'virtual_qty' && order_quantity > virtual_qty) || + (order_quantity > qty_available && order_quantity > virtual_qty) + ); + + if (should_restrict) { + const confirmed = this.popup.add(RestrictStockPopup, { + body: product.display_name, + pro_id: product.id, + }); + + } else { + await super.addProductToCurrentOrder(...args); } }, -}); +}); \ No newline at end of file diff --git a/pos_restrict_product_stock/static/src/js/RestrictStockPopup.js b/pos_restrict_product_stock/static/src/js/RestrictStockPopup.js index 4eca14794..54909f8ea 100644 --- a/pos_restrict_product_stock/static/src/js/RestrictStockPopup.js +++ b/pos_restrict_product_stock/static/src/js/RestrictStockPopup.js @@ -5,16 +5,17 @@ import { AbstractAwaitablePopup } from "@point_of_sale/app/popup/abstract_awaitable_popup"; class RestrictStockPopup extends AbstractAwaitablePopup { + _OrderProduct() { // On clicking order product button on popup, it will add product to orderline - if(this.props.pro_id){ - var product = this.env.services.pos.db.get_product_by_id(this.props.pro_id) - product.order_status = true - this.env.services.pos.selectedOrder.add_product(product); - } - this.props.resolve(true); - this.cancel(); - } + if(this.props.pro_id){ + var product = this.env.services.pos.db.get_product_by_id(this.props.pro_id) + product.order_status = true + this.env.services.pos.selectedOrder.add_product(product); + } + this.props.resolve(true); + this.props.close(); + } } RestrictStockPopup.template = 'RestrictStockPopup'; export default RestrictStockPopup; diff --git a/pos_restrict_product_stock/static/src/xml/RestrictStockPopup.xml b/pos_restrict_product_stock/static/src/xml/RestrictStockPopup.xml index cc5f0ef1c..c8bb1f95d 100644 --- a/pos_restrict_product_stock/static/src/xml/RestrictStockPopup.xml +++ b/pos_restrict_product_stock/static/src/xml/RestrictStockPopup.xml @@ -23,4 +23,4 @@ - +