From 3735f6c961aac738bd7b604b73ebae253c06ea4e Mon Sep 17 00:00:00 2001 From: "Valentin Vallaeys (vava)" Date: Mon, 2 Oct 2023 17:24:53 +0200 Subject: [PATCH] [FIX] website_sale(_*): fix zero price sale * product_configurator, comparison, stock(_wishlist) Before this commit, the option "Prevent Sale of Zero Price Product" would still allow some free products to be added to the cart (accessory, optional and alternative products). This commit makes sure no free product can be added to cart if this option is activated. Also, this option was conflicting with some other options and not well handled in bridge modules. This commit improves the UX when this option is activated. task-2983615 closes odoo/odoo#143626 X-original-commit: 158f622f00bad7f3b24b81cfa715601f5ff7022a Part-of: odoo/odoo#143504 Signed-off-by: Vallaeys Valentin (vava) --- addons/website_sale/models/sale_order.py | 4 ++++ addons/website_sale/models/website_snippet_filter.py | 2 ++ addons/website_sale/views/templates.xml | 2 +- .../views/website_sale_comparison_template.xml | 2 +- addons/website_sale_product_configurator/controllers/main.py | 4 +++- addons/website_sale_product_configurator/views/templates.xml | 2 +- .../src/xml/website_sale_stock_product_availability.xml | 2 +- .../static/src/xml/product_availability.xml | 4 +++- 8 files changed, 16 insertions(+), 6 deletions(-) diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py index 7b543af7ec9..fae5b696b6c 100644 --- a/addons/website_sale/models/sale_order.py +++ b/addons/website_sale/models/sale_order.py @@ -368,6 +368,10 @@ class SaleOrder(models.Model): product.id not in product_ids and product.filtered_domain(self.env['product.product']._check_company_domain(line.company_id)) and product._is_variant_possible(parent_combination=combination) + and ( + not self.website_id.prevent_zero_price_sale + or product._get_contextual_price() + ) ) return random.sample(all_accessory_products, len(all_accessory_products)) diff --git a/addons/website_sale/models/website_snippet_filter.py b/addons/website_sale/models/website_snippet_filter.py index 9e8a1f8071a..23416dab329 100644 --- a/addons/website_sale/models/website_snippet_filter.py +++ b/addons/website_sale/models/website_snippet_filter.py @@ -170,6 +170,8 @@ class WebsiteSnippetFilter(models.Model): excluded_products |= current_template.product_variant_ids included_products = current_template.alternative_product_ids.product_variant_ids products = included_products - excluded_products + if website.prevent_zero_price_sale: + products = products.filtered(lambda p: p._get_contextual_price()) if products: domain = expression.AND([ domain, diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml index cad30f3403e..1fe02017b73 100644 --- a/addons/website_sale/views/templates.xml +++ b/addons/website_sale/views/templates.xml @@ -215,7 +215,7 @@
- + diff --git a/addons/website_sale_comparison/views/website_sale_comparison_template.xml b/addons/website_sale_comparison/views/website_sale_comparison_template.xml index 1b10ff8cac3..9a405f2314a 100644 --- a/addons/website_sale_comparison/views/website_sale_comparison_template.xml +++ b/addons/website_sale_comparison/views/website_sale_comparison_template.xml @@ -163,7 +163,7 @@ class="btn btn-primary btn_cta"> Contact Us - + Add to Cart diff --git a/addons/website_sale_product_configurator/controllers/main.py b/addons/website_sale_product_configurator/controllers/main.py index 6516e181175..343ec003402 100644 --- a/addons/website_sale_product_configurator/controllers/main.py +++ b/addons/website_sale_product_configurator/controllers/main.py @@ -16,7 +16,9 @@ class WebsiteSaleProductConfiguratorController(Controller): product_template = product.product_tmpl_id combination = request.env['product.template.attribute.value'].browse(variant_values) has_optional_products = product.optional_product_ids.filtered( - lambda p: p._is_add_to_cart_possible(combination)) + lambda p: p._is_add_to_cart_possible(combination) + and (not request.website.prevent_zero_price_sale or p._get_contextual_price()) + ) already_configured = bool(combination) if not force_dialog and not has_optional_products and ( diff --git a/addons/website_sale_product_configurator/views/templates.xml b/addons/website_sale_product_configurator/views/templates.xml index fec659110e0..775ed93bcf7 100644 --- a/addons/website_sale_product_configurator/views/templates.xml +++ b/addons/website_sale_product_configurator/views/templates.xml @@ -133,7 +133,7 @@ - + diff --git a/addons/website_sale_stock/static/src/xml/website_sale_stock_product_availability.xml b/addons/website_sale_stock/static/src/xml/website_sale_stock_product_availability.xml index ef1c37026d7..0d7566f1166 100644 --- a/addons/website_sale_stock/static/src/xml/website_sale_stock_product_availability.xml +++ b/addons/website_sale_stock/static/src/xml/website_sale_stock_product_availability.xml @@ -2,7 +2,7 @@ - +
diff --git a/addons/website_sale_stock_wishlist/static/src/xml/product_availability.xml b/addons/website_sale_stock_wishlist/static/src/xml/product_availability.xml index 0f12e8605f2..3983a8908b2 100644 --- a/addons/website_sale_stock_wishlist/static/src/xml/product_availability.xml +++ b/addons/website_sale_stock_wishlist/static/src/xml/product_availability.xml @@ -2,7 +2,9 @@ -
+