Browse Source

Nov 21: [FIX] Bug Fixed 'pos_restrict_product_stock'

pull/254/merge
Cybrosys Technologies 5 months ago
parent
commit
2a79535613
  1. 3
      pos_restrict_product_stock/__manifest__.py
  2. 5
      pos_restrict_product_stock/doc/RELEASE_NOTES.md
  3. 1
      pos_restrict_product_stock/models/__init__.py
  4. 36
      pos_restrict_product_stock/models/product_product.py
  5. 11
      pos_restrict_product_stock/static/src/js/OutOfStockPopup.js
  6. 34
      pos_restrict_product_stock/static/src/js/ProductItem.js
  7. 18
      pos_restrict_product_stock/static/src/js/ProductScreen.js
  8. 19
      pos_restrict_product_stock/static/src/xml/OutOfStockPopup.xml

3
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/css/display_stock.css',
'/pos_restrict_product_stock/static/src/js/RestrictStockPopup.js', '/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/ProductScreen.js',
'/pos_restrict_product_stock/static/src/js/OutOfStockPopup.js',
'/pos_restrict_product_stock/static/src/js/ProductItem.js',
], ],
'web.assets_qweb': [ 'web.assets_qweb': [
'/pos_restrict_product_stock/static/src/xml/ProductItem.xml', '/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/RestrictStockPopup.xml',
'/pos_restrict_product_stock/static/src/xml/OutOfStockPopup.xml',
], ],
}, },
'images': ['static/description/banner.jpg'], 'images': ['static/description/banner.jpg'],

5
pos_restrict_product_stock/doc/RELEASE_NOTES.md

@ -4,3 +4,8 @@
#### Version 15.0.1.0.0 #### Version 15.0.1.0.0
#### ADD #### ADD
- Initial Commit for Display Stock in POS | Restrict Out-of-Stock Products in POS - 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.

1
pos_restrict_product_stock/models/__init__.py

@ -20,3 +20,4 @@
# #
############################################################################### ###############################################################################
from . import pos_config from . import pos_config
from . import product_product

36
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(<https://www.cybrosys.com>)
# 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 <http://www.gnu.org/licenses/>.
#
###############################################################################
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

11
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);

34
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);

18
pos_restrict_product_stock/static/src/js/ProductScreen.js

@ -24,5 +24,23 @@ const RestrictProductScreen = (ProductScreen) => class RestrictProductScreen ext
await super._clickProduct(event) 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); Registries.Component.extend(ProductScreen, RestrictProductScreen);

19
pos_restrict_product_stock/static/src/xml/OutOfStockPopup.xml

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<template id="template" xml:space="preserve">
<!--This template is used for registering a popup for restrict product from ordering-->
<t t-name="OutOfStockPopup" owl="1">
<div role="dialog" class="modal-dialog">
<div class="popup popup-text popup-med restrict-stock-popup">
<div class="title">Product Out of Stock</div>
<div style="height:100px; margin-top:20px;">
<span style="color:#811331"><t t-esc="props.body"/></span> is out of stock.
</div>
<div class="footer">
<div class="button cancel" style="color:red" t-on-click="cancel">
Cancel
</div>
</div>
</div>
</div>
</t>
</template>
Loading…
Cancel
Save