diff --git a/website_sale_product_minimal_price/README.rst b/website_sale_product_minimal_price/README.rst index ba6b06b96c..a3785b9696 100644 --- a/website_sale_product_minimal_price/README.rst +++ b/website_sale_product_minimal_price/README.rst @@ -26,8 +26,8 @@ Website Sale Product Minimal Price |badge1| |badge2| |badge3| |badge4| |badge5| This module extends the functionality of website sale module to allow to -display the minimal price in '/shop' view when product has extra variants -price and set order by extra price in product's view. +display the minimal price in '/shop' view when product has distinct variants +price and set order by minimal price in product's view. **Table of contents** @@ -38,10 +38,10 @@ Usage ===== #. Go to backend and set a product with variants and extra price by attribute - value. + value or define a distinct prices in public price list for this variant. #. Go to Website Shop. #. You will see that in main products view appears the text "From " with - minimal price if the product has a diferent extra prices by attribute. + minimal price if the product has a distinct prices by attribute. #. Click on product, the price displayed is the minimal variant price. Bug Tracker diff --git a/website_sale_product_minimal_price/models/product_template.py b/website_sale_product_minimal_price/models/product_template.py index a1d0c4c141..5e19bf9d20 100644 --- a/website_sale_product_minimal_price/models/product_template.py +++ b/website_sale_product_minimal_price/models/product_template.py @@ -1,35 +1,29 @@ # Copyright 2019 Tecnativa - Sergio Teruel # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import api, fields, models +from odoo import fields, models class ProductTemplate(models.Model): _inherit = 'product.template' - has_variant_price_extra = fields.Boolean( - compute='_compute_has_variant_price_extra', - store=True, - string='Has variants with price extra', + has_distinct_variant_price = fields.Boolean( + compute='_compute_has_distinct_variant_price', + string='Has variants with distinct extra', ) - @api.depends( - 'product_variant_ids.attribute_value_ids.price_ids.price_extra') - def _compute_has_variant_price_extra(self): + def _compute_has_distinct_variant_price(self): for template in self: - if (template.product_variant_count and len(set( - template.product_variant_ids.mapped('price_extra'))) != 1): - template.has_variant_price_extra = True + if template.product_variant_count > 1: + prices = template.product_variant_ids.mapped('website_price') + if len(prices) > 1: + template.has_distinct_variant_price = True def _website_price(self): - templates = self.filtered( - lambda x: ( - x.product_variant_count > 1 and any( - [v.price_extra != 0.0 for v in x.product_variant_ids])) - ) + templates = self.filtered(lambda x: x.product_variant_count > 1) super(ProductTemplate, self - templates)._website_price() for product in templates: variant = product.product_variant_ids.sorted( - key=lambda v: v.price_extra)[:1] + key=lambda p: p.website_price)[:1] product.website_price = variant.website_price product.website_public_price = variant.website_public_price product.website_price_difference = variant.website_price_difference diff --git a/website_sale_product_minimal_price/readme/DESCRIPTION.rst b/website_sale_product_minimal_price/readme/DESCRIPTION.rst index f4f13e65e4..09c47abbba 100644 --- a/website_sale_product_minimal_price/readme/DESCRIPTION.rst +++ b/website_sale_product_minimal_price/readme/DESCRIPTION.rst @@ -1,3 +1,3 @@ This module extends the functionality of website sale module to allow to -display the minimal price in '/shop' view when product has extra variants -price and set order by extra price in product's view. +display the minimal price in '/shop' view when product has distinct variants +price and set order by minimal price in product's view. diff --git a/website_sale_product_minimal_price/readme/USAGE.rst b/website_sale_product_minimal_price/readme/USAGE.rst index e074c0c211..5e5e861d43 100644 --- a/website_sale_product_minimal_price/readme/USAGE.rst +++ b/website_sale_product_minimal_price/readme/USAGE.rst @@ -1,6 +1,6 @@ #. Go to backend and set a product with variants and extra price by attribute - value. + value or define a distinct prices in public price list for this variant. #. Go to Website Shop. #. You will see that in main products view appears the text "From " with - minimal price if the product has a diferent extra prices by attribute. + minimal price if the product has a distinct prices by attribute. #. Click on product, the price displayed is the minimal variant price. diff --git a/website_sale_product_minimal_price/static/description/index.html b/website_sale_product_minimal_price/static/description/index.html index 2432706364..8c0a9db721 100644 --- a/website_sale_product_minimal_price/static/description/index.html +++ b/website_sale_product_minimal_price/static/description/index.html @@ -369,8 +369,8 @@
This module extends the functionality of website sale module to allow to -display the minimal price in ‘/shop’ view when product has extra variants -price and set order by extra price in product’s view.
+display the minimal price in ‘/shop’ view when product has distinct variants +price and set order by minimal price in product’s view.Table of contents