From 2228b92f467db40ea1d12879266591b935e7ee8d Mon Sep 17 00:00:00 2001 From: Ethan Vincent Date: Fri, 16 Feb 2024 12:20:17 +0100 Subject: [PATCH] [FIX] website_sale: check settings for price comparison **Current behavior:** Enabling the 'Comparison Price' setting and filling out the field will result in this strikethrough price appearing even after disabling the setting. **Expected behavior:** The strikethrough comparison price will only appear when the corresponding setting is enabled in the database settings. **Steps to reproduce:** 1. Enable the 'Comparison Price' setting in website settings 2. Select a product on the 'Shop' page of the website and edit it so it has a comparison price != to its regular one 3. Save product changes, go back to the db settings and disable the 'Comparison Price' setting 4. Go back to the website 'Shop' page and observe that the strikethrough comparison price is still displayed **Cause of the issue:** In the product.template model in website_sale, the price values are modified to those informed by the compare_list_price value independent of the current value of the corresponding database setting. It only checks if there is non-False value in the field. **Fix:** Check if the user belongs to the group corresponding to this db settings prior to modifying the product template to display the strikethrough compare price. opw-3705079 closes odoo/odoo#154573 X-original-commit: 0d76bdb23d26f777587c9c30d5479fdf3c694937 Signed-off-by: Vincent Ethan Signed-off-by: Victor Feyens (vfe) --- addons/website_sale/models/product_template.py | 3 ++- .../tests/test_website_sale_show_compare_list_price.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/website_sale/models/product_template.py b/addons/website_sale/models/product_template.py index 9e3b1276358..174e06ee043 100644 --- a/addons/website_sale/models/product_template.py +++ b/addons/website_sale/models/product_template.py @@ -261,6 +261,7 @@ class ProductTemplate(models.Model): sales_prices = pricelist._get_products_price(self, 1.0) show_discount = pricelist and pricelist.discount_policy == 'without_discount' + show_strike_price = self.env.user.has_group('website_sale.group_product_price_comparison') base_sales_prices = self._price_compute('list_price', currency=currency) website = self.env['website'].get_current_website() @@ -279,7 +280,7 @@ class ProductTemplate(models.Model): base_price = None price_list_contains_template = currency.compare_amounts(price_reduce, base_sales_prices[template.id]) != 0 - if template.compare_list_price: + if template.compare_list_price and show_strike_price: # The base_price becomes the compare list price and the price_reduce becomes the price base_price = template.compare_list_price if not price_list_contains_template: diff --git a/addons/website_sale/tests/test_website_sale_show_compare_list_price.py b/addons/website_sale/tests/test_website_sale_show_compare_list_price.py index a448bcaa3a9..ab3312034c9 100644 --- a/addons/website_sale/tests/test_website_sale_show_compare_list_price.py +++ b/addons/website_sale/tests/test_website_sale_show_compare_list_price.py @@ -1,4 +1,8 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.fields import Command from odoo.tests import tagged + from odoo.addons.account.tests.common import AccountTestInvoicingHttpCommon @@ -112,4 +116,9 @@ class WebsiteSaleShopPriceListCompareListPriceDispayTests(AccountTestInvoicingHt }) def test_compare_list_price_price_list_display(self): + self.env.user.write({ + 'groups_id': [Command.link( + self.env.ref('website_sale.group_product_price_comparison').id + )], + }) self.start_tour("/", 'compare_list_price_price_list_display', login=self.env.user.login)