-
-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[11.0][IMP] website_sale_product_minimal_price: Order by minimal vari…
…ant price (from pricelists or extra variant price)
- Loading branch information
1 parent
ec6b072
commit 4735d41
Showing
6 changed files
with
27 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 11 additions & 17 deletions
28
website_sale_product_minimal_price/models/product_template.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters