From 6ff05066582133f90d30b147aab27e38ba3ad9cd Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Wed, 8 Feb 2023 09:36:38 +0000 Subject: [PATCH] [FIX] website_sale, website_sale_stock: prevent out of stock Steps to reproduce: - create a product; - disable the continue selling option for the out-of-stock; - do not have a stock quantity for this product. - go to ecommerce; - without click on the product, add it in the cart with the cart icon (on the picture). Issue: It is possible to add the product to the cart. If we repeat this several times, we will create quotations. Solution: Hide the button if the product is a storable product and we don't want to sell it if we have no stock. We also check the quantity available. opw-3148069 closes odoo/odoo#120176 X-original-commit: bf4b5962c396101f242822058b5ddf815408e3f8 Signed-off-by: Antoine Vandevenne (anv) Signed-off-by: Lefebvre Thomas (thle) --- addons/website_sale_stock/models/product_product.py | 3 +++ addons/website_sale_stock/models/product_template.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/addons/website_sale_stock/models/product_product.py b/addons/website_sale_stock/models/product_product.py index 0df5f6ec3d8..46ef444eaee 100644 --- a/addons/website_sale_stock/models/product_product.py +++ b/addons/website_sale_stock/models/product_product.py @@ -30,6 +30,9 @@ class ProductProduct(models.Model): combination_info = self.with_context(website_sale_stock_get_quantity=True).product_tmpl_id._get_combination_info(product_id=self.id) return combination_info['product_type'] == 'product' and combination_info['free_qty'] <= 0 + def _website_show_quick_add(self): + return (self.allow_out_of_stock_order or not self._is_sold_out()) and super()._website_show_quick_add() + def _send_availability_email(self): for product in self.search([('stock_notification_partner_ids', '!=', False)]): if product._is_sold_out(): diff --git a/addons/website_sale_stock/models/product_template.py b/addons/website_sale_stock/models/product_template.py index 7346bcec16e..0b712735548 100644 --- a/addons/website_sale_stock/models/product_template.py +++ b/addons/website_sale_stock/models/product_template.py @@ -59,3 +59,6 @@ class ProductTemplate(models.Model): def _is_sold_out(self): return self.product_variant_id._is_sold_out() + + def _website_show_quick_add(self): + return (self.allow_out_of_stock_order or not self._is_sold_out()) and super()._website_show_quick_add()