[FIX] website_sale: variants view, currency price and price diff

Before this commit:
1. When enabling 'List View of Variants' on a product page, it would not
   replace the variant normal view as it should since the code being replaced
   is included in the code replacing it.
2.The badge specifying the price difference between the variance and the
  product base price would be calculated by taking the price_extra of the
  variance attribute and converting it in the user currency which was not
  correct if a pricelist was set on the product variant because the price diff
  would then be (the variant price set on the pricelist) - (product base price)
  Note: this is about the 'List View of Variants' mode, not the normal mode
        which list variant attribute and not variant itself
3. The strikethrough amount was not in the user currency

Step to reproduce:
  - Enable variants & pricelists
  - Enable multi-currency and activate 'COP' as second currency (you may want
    to change the currency symbol on edit mode since it is also '$')
  - Go to iPad Retina Display product page in shop
  - Enable 'List View of Variants' in 'Customize'
  - Both Variants selection mode are visible (bug 1)
  - The third variant shows '+$ 50.40' which is the diff between the
    strikethrough prices (in fact the sum of the price_extra of the product
    variant attributes, +50,40 on the 32GO attribute in this case)
    It should show '+$ 40.32' since the price change from $600 to $640.32.
    This is bug n°2
  - Change Public Pricelist currency from USD to COP
  - Back on iPad page, change between the 3 product variants, you will see
    the $ price strikedthrough instead of the COP one:
    Strikedthrough: 750 (it should be 1 714 491,47)
    Price: 1 371 593,17
    This is bug 3
  - You can notice the bug n°2 being more visible since it shows
    '+$ 115 213,83' instead of '+ 92 171.07'
  - Remove the iPad Retina from Public Pricelist and add iPad Retina 32Go
    variant to it with a fix price of $1 000 000.
  - '32Gb, 2.4GHz, White' variant cost $1 000 000 but shows '+ 115 213.83'
    instead of '- 714 491.47' since the base price of Retina is
    '1 714 491.47'.
  - You can play with the pricelist price for this variant up and down, the
    diff price shown in the badge will always be 115 213.83 since it will
    always calculate it by summing all the variant's attribute price_extra
    and then converting it to the user currency.

This closes #14094, closes #22553
This commit is contained in:
Romain Derie
2018-02-21 12:18:56 +01:00
parent e544ec8df7
commit 2120e667b9
+4 -10
View File
@@ -449,19 +449,13 @@
<template id="product_variants" inherit_id="website_sale.product" active="False" customize_show="True" name="List View of Variants">
<xpath expr="//t[@t-placeholder='select']" position="replace">
<input type="hidden" t-if="len(product.product_variant_ids) == 1" name="product_id" t-att-value="product.product_variant_ids[0].id"/>
<t t-call="website_sale.variants">
<t t-set="ul_class" t-value="'nav-stacked'"/>
</t>
<t t-if="len(product.product_variant_ids) &gt; 1">
<label label-default="label-default" class="radio" t-foreach="product.product_variant_ids" t-as="variant_id">
<input type="radio" name="product_id" class="js_product_change" t-att-checked="'checked' if variant_id_index == 0 else ''" t-att-value="variant_id.id" t-att-data-lst_price="variant_id.lst_price" t-att-data-price="variant_id.price"/>
<input type="radio" name="product_id" class="js_product_change" t-att-checked="'checked' if variant_id_index == 0 else ''" t-att-value="variant_id.id" t-att-data-lst_price="compute_currency(variant_id.lst_price)" t-att-data-price="variant_id.price"/>
<span t-esc="variant_id.name_get()[0][1]"/>
<span class="badge" t-if="variant_id.price_extra">
<t t-esc="variant_id.price_extra > 0 and '+' or ''"/><span t-field="variant_id.price_extra" style="white-space: nowrap;" t-field-options='{
"widget": "monetary",
"from_currency": "product.currency_id",
"display_currency": "website.currency_id"
}'/>
<t t-set="diff_price" t-value="variant_id.price - variant_id.product_tmpl_id.price"/>
<span class="badge" t-if="diff_price != 0">
<t t-esc="diff_price > 0 and '+' or '-'"/><span t-esc="abs(diff_price)" t-esc-options='{"widget": "monetary", "display_currency": "website.currency_id"}'/>
</span>
</label>
</t>