I have this code that restricts the sale of the products from POS if they are out of stock. But it works when i select the product and then click on payment button. When I click on payment button on POS Session it will display a message for out of stock products. I want to add another feature, I want this message to be displayed when I click on out of stock products. For example, if a product is out of stock, when I click on the product it should give me the warning message. Out of stock products cannot be selected. So instead of selecting the out of stock products and then displaying the message while payment, I want to display the message when the product is selected. Can anyone help me to make the code work for odoo 17. I am new to Odoo POS development. Please help me out, Thank you.
patch(Order.prototype, {
async pay() {
let order = this.env.services.pos.get_order();
let lines = order.get_orderlines();
let pos_config = this.env.services.pos.config;
let config_id = this.env.services.pos.config.id;
let prod_used_qty = {};
let outOfStockProducts = [];
let restrict = false;
if (pos_config.restrict_zero_qty) {
lines.forEach(line => {
let prd = line.product;
if (prd.type === 'product') {
if (prd.id in prod_used_qty) {
let old_qty = prod_used_qty[prd.id][1];
prod_used_qty[prd.id] = [prd.qty_available, line.quantity + old_qty];
} else {
prod_used_qty[prd.id] = [prd.qty_available, line.quantity];
}
// Check if product is out of stock
if (prd.qty_available <= 0) {
restrict = true;
outOfStockProducts.push(prd.display_name);
}
}
});
// Check if any products are out of stock
if (restrict === true) {
let warning = _t('Out of stock products cannot be sold: n') + outOfStockProducts.join(', n');
this.env.services.pos.popup.add(ErrorPopup, {
title: _t('Out of Stock Products'),
body: _t(warning),
});
} else {
// Proceed with payment if no products are out of stock
super.pay();
}
} else {
// Proceed with payment if zero quantity restriction is not enabled
super.pay();
}
},
});
How can i make this for odoo 17?
I have tried searching about this but didn't get any solution
afrah naaz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.