From 2a79535613e71b7b262302780a182c4ded9e46b4 Mon Sep 17 00:00:00 2001 From: Cybrosys Technologies Date: Thu, 21 Nov 2024 13:40:06 +0530 Subject: [PATCH] Nov 21: [FIX] Bug Fixed 'pos_restrict_product_stock' --- pos_restrict_product_stock/__manifest__.py | 3 ++ .../doc/RELEASE_NOTES.md | 5 +++ pos_restrict_product_stock/models/__init__.py | 1 + .../models/product_product.py | 36 +++++++++++++++++++ .../static/src/js/OutOfStockPopup.js | 11 ++++++ .../static/src/js/ProductItem.js | 34 ++++++++++++++++++ .../static/src/js/ProductScreen.js | 18 ++++++++++ .../static/src/xml/OutOfStockPopup.xml | 19 ++++++++++ 8 files changed, 127 insertions(+) create mode 100644 pos_restrict_product_stock/models/product_product.py create mode 100644 pos_restrict_product_stock/static/src/js/OutOfStockPopup.js create mode 100644 pos_restrict_product_stock/static/src/js/ProductItem.js create mode 100644 pos_restrict_product_stock/static/src/xml/OutOfStockPopup.xml diff --git a/pos_restrict_product_stock/__manifest__.py b/pos_restrict_product_stock/__manifest__.py index e0ddbf41f..cdadb4ef2 100644 --- a/pos_restrict_product_stock/__manifest__.py +++ b/pos_restrict_product_stock/__manifest__.py @@ -42,10 +42,13 @@ '/pos_restrict_product_stock/static/src/css/display_stock.css', '/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/OutOfStockPopup.js', + '/pos_restrict_product_stock/static/src/js/ProductItem.js', ], 'web.assets_qweb': [ '/pos_restrict_product_stock/static/src/xml/ProductItem.xml', '/pos_restrict_product_stock/static/src/xml/RestrictStockPopup.xml', + '/pos_restrict_product_stock/static/src/xml/OutOfStockPopup.xml', ], }, 'images': ['static/description/banner.jpg'], diff --git a/pos_restrict_product_stock/doc/RELEASE_NOTES.md b/pos_restrict_product_stock/doc/RELEASE_NOTES.md index 94daf58af..dfef2abd9 100644 --- a/pos_restrict_product_stock/doc/RELEASE_NOTES.md +++ b/pos_restrict_product_stock/doc/RELEASE_NOTES.md @@ -4,3 +4,8 @@ #### Version 15.0.1.0.0 #### ADD - Initial Commit for Display Stock in POS | Restrict Out-of-Stock Products in POS +- +#### 18.11.2024 +#### Version 15.0.1.0.1 +### UPDT +- Restricted payment if an item in the order is out of stock.Update product stock without refreshing the page. diff --git a/pos_restrict_product_stock/models/__init__.py b/pos_restrict_product_stock/models/__init__.py index 290d1ec05..bc63fc736 100644 --- a/pos_restrict_product_stock/models/__init__.py +++ b/pos_restrict_product_stock/models/__init__.py @@ -20,3 +20,4 @@ # ############################################################################### from . import pos_config +from . import product_product diff --git a/pos_restrict_product_stock/models/product_product.py b/pos_restrict_product_stock/models/product_product.py new file mode 100644 index 000000000..be7568c53 --- /dev/null +++ b/pos_restrict_product_stock/models/product_product.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies() +# Author: Gayathri V(odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################### +from odoo import api, models + + +class ProductProduct(models.Model): + + _inherit = 'product.product' + + @api.model + def get_product_quantity(self): + """ + Retrieves a list of products that are available in the Point of Sale (POS) system, + including their current available quantity and virtual available quantity. + """ + products= self.search_read([('available_in_pos','=',True)],fields=['id', 'qty_available','virtual_available']) + return products diff --git a/pos_restrict_product_stock/static/src/js/OutOfStockPopup.js b/pos_restrict_product_stock/static/src/js/OutOfStockPopup.js new file mode 100644 index 000000000..8dcf08a80 --- /dev/null +++ b/pos_restrict_product_stock/static/src/js/OutOfStockPopup.js @@ -0,0 +1,11 @@ +/** @odoo-module **/ +/* + * This file is used to store a popup for stocks out of stock for forced orders. + */ +import AbstractAwaitablePopup from 'point_of_sale.AbstractAwaitablePopup'; +import Registries from 'point_of_sale.Registries'; + +class OutOfStockPopup extends AbstractAwaitablePopup { +} +OutOfStockPopup.template = 'OutOfStockPopup'; +Registries.Component.add(OutOfStockPopup); \ No newline at end of file diff --git a/pos_restrict_product_stock/static/src/js/ProductItem.js b/pos_restrict_product_stock/static/src/js/ProductItem.js new file mode 100644 index 000000000..43bee6009 --- /dev/null +++ b/pos_restrict_product_stock/static/src/js/ProductItem.js @@ -0,0 +1,34 @@ +/** @odoo-module **/ +import Registries from 'point_of_sale.Registries'; +import ProductItem from 'point_of_sale.ProductItem'; +var rpc = require('web.rpc'); +const { hooks } = owl; +const { onWillStart } = hooks; + +const ProductStockDisplay = (ProductItem) => class ProductStockDisplay extends ProductItem { + + async willStart() { + var self = this; + var result = null + await rpc.query({ + model: "product.product", + method: "get_product_quantity", + }).then(function (data) { + // Iterate through each product in the data received from the RPC query + result=data + data.forEach(function (productData) { + // Find the corresponding product in product_by_id by matching product ID + var productInDb = self.env.pos.db.product_by_id[productData.id]; + if (productInDb) { + // Compare qty_available and virtual_available between the two data sets + if (productInDb.qty_available !== productData.qty_available || productInDb.virtual_available !== productData.virtual_available) { + // If there's a change, update the product in product_by_id + productInDb.qty_available = productData.qty_available; + productInDb.virtual_available = productData.virtual_available; + } + } + }); + }); + } +} +Registries.Component.extend(ProductItem, ProductStockDisplay); \ 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 ba8867e22..0793d99e8 100644 --- a/pos_restrict_product_stock/static/src/js/ProductScreen.js +++ b/pos_restrict_product_stock/static/src/js/ProductScreen.js @@ -24,5 +24,23 @@ const RestrictProductScreen = (ProductScreen) => class RestrictProductScreen ext await super._clickProduct(event) } } + async _onClickPay(){ + var type = this.env.pos.config.stock_type + var out_of_stock = false + for (let rec of this.env.pos.get_order().orderlines.models) { + if (this.env.pos.config.is_restrict_product && ((type == 'qty_on_hand') && (rec.quantity > rec.product.qty_available)) | ((type == 'virtual_qty') && (rec.quantity > rec.product.virtual_available)) | + ((rec.quantity > rec.product.qty_available) && (rec.quantity > rec.product.virtual_available))) { + out_of_stock = true + this.showPopup("OutOfStockPopup", { + body: rec.product.display_name, + pro_id: rec.product.id + }); + break; + } + } + if (out_of_stock==false){ + await super._onClickPay() +} + } } Registries.Component.extend(ProductScreen, RestrictProductScreen); diff --git a/pos_restrict_product_stock/static/src/xml/OutOfStockPopup.xml b/pos_restrict_product_stock/static/src/xml/OutOfStockPopup.xml new file mode 100644 index 000000000..106d36f7f --- /dev/null +++ b/pos_restrict_product_stock/static/src/xml/OutOfStockPopup.xml @@ -0,0 +1,19 @@ + +