diff --git a/pos_restrict_product_stock/__manifest__.py b/pos_restrict_product_stock/__manifest__.py index 26eb89675..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.1.0.0', + '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""", @@ -37,6 +37,7 @@ 'point_of_sale._assets_pos': [ '/pos_restrict_product_stock/static/src/js/RestrictStockPopup.js', '/pos_restrict_product_stock/static/src/js/ProductScreen.js', + '/pos_restrict_product_stock/static/src/js/OrderScreen.js', '/pos_restrict_product_stock/static/src/css/display_stock.css', '/pos_restrict_product_stock/static/src/xml/ProductItem.xml', '/pos_restrict_product_stock/static/src/xml/RestrictStockPopup.xml', diff --git a/pos_restrict_product_stock/doc/RELEASE_NOTES.md b/pos_restrict_product_stock/doc/RELEASE_NOTES.md index 84fa35507..b1f1b001e 100644 --- a/pos_restrict_product_stock/doc/RELEASE_NOTES.md +++ b/pos_restrict_product_stock/doc/RELEASE_NOTES.md @@ -4,3 +4,9 @@ #### Version 17.0.1.0.0 #### ADD - Initial Commit for Display Stock in POS | Restrict Out-of-Stock Products in POS + +#### 30.10.2024 +#### 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. \ No newline at end of file diff --git a/pos_restrict_product_stock/static/src/js/OrderScreen.js b/pos_restrict_product_stock/static/src/js/OrderScreen.js new file mode 100644 index 000000000..f1da183ae --- /dev/null +++ b/pos_restrict_product_stock/static/src/js/OrderScreen.js @@ -0,0 +1,35 @@ +/** @odoo-module */ + +import { Order } from "@point_of_sale/app/store/models"; +import { patch } from "@web/core/utils/patch"; +import RestrictStockPopup from "@pos_restrict_product_stock/js/RestrictStockPopup" + +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 + } + } + + }) \ 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 ce2f9af10..5bada1f09 100644 --- a/pos_restrict_product_stock/static/src/js/RestrictStockPopup.js +++ b/pos_restrict_product_stock/static/src/js/RestrictStockPopup.js @@ -7,9 +7,13 @@ import { AbstractAwaitablePopup } from "@point_of_sale/app/popup/abstract_awaita 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.cancel(); + } + this.props.resolve(true); + this.cancel(); } } RestrictStockPopup.template = 'RestrictStockPopup';