Skip to content
Snippets Groups Projects
Commit 7e202c09 authored by Achraf's avatar Achraf
Browse files

[FIX] website_sale: Adapt compare_list_price widget currency to match list_price

- Install `website_sale`
- Go to settings
- Enable 'Comparison Price'
- Go to products
- Open a random product
- Put a random `Compare to Price` (example $400 with a sales Price to $295)
- Click on smart button `Go To Website`

With $ 1 = 0.5 €
Before:

With `Public Pricelist`: `$ 300.00 ($ 400.00)`
With `EUR` pricelist: `150.00 € ($ 400.00)`

After:

With `Public Pricelist`: `$ 300.00 ($ 400.00)`
With `EUR` pricelist: `150.00 € (200.00 €)`

backport of https://github.com/odoo/odoo/pull/87134



closes odoo/odoo#133484

Signed-off-by: default avatarAchraf Ben Azzouz (abz) <abz@odoo.com>
parent 41b0edf7
No related branches found
No related tags found
No related merge requests found
......@@ -273,6 +273,12 @@ class ProductTemplate(models.Model):
fields.Date.today())
has_discounted_price = pricelist.currency_id.compare_amounts(list_price, price) == 1
prevent_zero_price_sale = not price and current_website.prevent_zero_price_sale
compare_list_price = self.compare_list_price
if pricelist and pricelist.currency_id != product.currency_id:
compare_list_price = self.currency_id._convert(self.compare_list_price, pricelist.currency_id, self.env.company,
fields.Datetime.now(), round=False)
combination_info.update(
base_unit_name=product.base_unit_name,
base_unit_price=product.base_unit_count and list_price / product.base_unit_count,
......@@ -281,6 +287,7 @@ class ProductTemplate(models.Model):
price_extra=price_extra,
has_discounted_price=has_discounted_price,
prevent_zero_price_sale=prevent_zero_price_sale,
compare_list_price=compare_list_price
)
return combination_info
......@@ -530,6 +537,10 @@ class ProductTemplate(models.Model):
list_price = self.env['ir.qweb.field.monetary'].value_to_html(
combination_info['list_price'], monetary_options
)
if combination_info['compare_list_price']:
list_price = self.env['ir.qweb.field.monetary'].value_to_html(
combination_info['compare_list_price'], monetary_options
)
return price, list_price if combination_info['has_discounted_price'] else None
......
......@@ -15,6 +15,15 @@ tour.register('compare_list_price_price_list_display', {
tourUtils.assertProductPrice("price_reduce", "4,000", "test_product_with_pricelist_and_compare_list_price"),
tourUtils.assertProductPrice("base_price", "4,500", "test_product_with_pricelist_and_compare_list_price"),
...tourUtils.selectPriceList('pricelist_other_currency'),
tourUtils.assertProductPrice("price_reduce", "2,000", "test_product_default"),
tourUtils.assertProductPrice("price_reduce", "4,000", "test_product_with_compare_list_price"),
tourUtils.assertProductPrice("base_price", "2,500", "test_product_with_compare_list_price"),
tourUtils.assertProductPrice("price_reduce", "4,000", "test_product_with_pricelist"),
tourUtils.assertProductPrice("price_reduce", "8,000", "test_product_with_pricelist_and_compare_list_price"),
tourUtils.assertProductPrice("base_price", "4,500", "test_product_with_pricelist_and_compare_list_price"),
...tourUtils.selectPriceList('pricelist_with_discount'),
tourUtils.assertProductPrice("price_reduce", "1,000", "test_product_default"),
......
......@@ -12,6 +12,8 @@ class WebsiteSaleShopPriceListCompareListPriceDispayTests(AccountTestInvoicingHt
ProductTemplate = cls.env['product.template']
Pricelist = cls.env['product.pricelist']
PricelistItem = cls.env['product.pricelist.item']
Currency = cls.env['res.currency']
CurrencyRate = cls.env['res.currency.rate']
# Cleanup existing pricelist.
cls.env['website'].search([]).write({'sequence': 1000})
......@@ -52,6 +54,17 @@ class WebsiteSaleShopPriceListCompareListPriceDispayTests(AccountTestInvoicingHt
'company_id': cls.env.company.id,
})
cls.test_custom_currency = Currency.create({
'name': "Test currency",
'symbol': 'A',
})
CurrencyRate.create({
'currency_id': cls.test_custom_currency.id,
'name': '2000-01-01',
'rate': 2.0,
})
# Three pricelists
Pricelist.search([]).write({'sequence': 1000})
cls.pricelist_default = Pricelist.create({
......@@ -77,6 +90,14 @@ class WebsiteSaleShopPriceListCompareListPriceDispayTests(AccountTestInvoicingHt
'sequence': 3,
'discount_policy': 'without_discount',
})
cls.pricelist_other_currency = Pricelist.create({
'name': 'pricelist_other_currency',
'website_id': website.id,
'company_id': cls.env.company.id,
'selectable': True,
'sequence': 4,
'currency_id': cls.test_custom_currency.id,
})
# Pricelist items
PricelistItem.create({
......
......@@ -1155,18 +1155,20 @@
<span class="oe_price" style="white-space: nowrap;" t-esc="combination_info['price']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/>
<span itemprop="price" style="display:none;" t-esc="combination_info['price']"/>
<span itemprop="priceCurrency" style="display:none;" t-esc="website.currency_id.name"/>
<span t-attf-class="text-danger oe_default_price ms-1 h5 {{'' if combination_info['has_discounted_price'] else 'd-none'}}" style="text-decoration: line-through; white-space: nowrap;"
t-esc="combination_info['list_price']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"
<span t-attf-class="text-danger oe_default_price ms-1 h5 {{'' if combination_info['has_discounted_price'] and not combination_info['compare_list_price'] else 'd-none'}}"
style="text-decoration: line-through; white-space: nowrap;"
t-esc="combination_info['list_price']"
t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"
itemprop="listPrice"
/>
<t t-if="is_view_active('website_sale.tax_indication')" t-call="website_sale.tax_indication"/>
<del t-if="product.compare_list_price">
<del t-if="combination_info['compare_list_price'] and (combination_info['compare_list_price'] &gt; combination_info['price'])">
<bdi dir="inherit">
<span t-field="product.compare_list_price"
<span t-esc="combination_info['compare_list_price']"
groups="website_sale.group_product_price_comparison"
t-options='{
"widget": "monetary",
"display_currency": product.currency_id,
"display_currency": website.currency_id,
}'/>
</bdi>
</del>
......@@ -1178,13 +1180,13 @@
"display_currency": product.currency_id,
}'/>
<t t-if="is_view_active('website_sale.tax_indication')" t-call="website_sale.tax_indication"/>
<del t-if="product.compare_list_price">
<del t-if="combination_info['compare_list_price'] and (combination_info['compare_list_price'] &gt; combination_info['price'])">
<bdi dir="inherit">
<span t-field="product.compare_list_price"
groups="website_sale.group_product_price_comparison"
t-options='{
"widget": "monetary",
"display_currency": product.currency_id,
"display_currency": website.currency_id,
}'/>
</bdi>
</del>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment