[FIX] website_sale, website_sale_options: currencies

Adaptations following rev. 1684ae4:
    The website pricelist is now dynamic, according
    to the pricelist chosen by the customer on the website.
    It's no longer a static pricelist, it's no longer
    the public user pricelist.

    Therefore, when computing the variants prices,
    the prices should no longer be converted
    from the public user pricelist to the current (context)
    pricelist, but from the product currency to the
    current pricelist chosen by the customer on the website

    In addition, when getting the unit price,
    `/shop/get_unit_price`,
    the website current pricelist should always be used,
    it should never fall back on the partner pricelist,
    as, it's the user who choose his pricelist from the website
    now (if he has specific set on his partner
    form, it's that one which is loaded by default, and which
    is returned by the website.pricelist_id)

    In addition, the displayed currency on the ecommerce
    must always be the current website pricelist currency

Adaptations following rev. 3622c0d:
    A product can have no company set (not required).
    Therefore, when attempting to set the `from_currency`
    to the product company currency, this could return
    `None`, if no company was set on the product.
    `product.currency_id` ensures to always return a currency
    for the product. It's the company currency
    if the product has a company set, otherwise it take it from
    the main company (`base.main_company`).

    In addition, when editing the product price from the website,
    the price must be displayed within the product currency,
    as, if changed by the user, it changes the product sales
    price directly on the product form, without any currency
    conversion applied or whatever.

opw-670898
opw-671100
This commit is contained in:
Denis Ledoux
2016-03-04 16:34:17 +01:00
parent 161e85a1dc
commit af174897ab
3 changed files with 16 additions and 23 deletions
+3 -9
View File
@@ -118,16 +118,13 @@ class website_sale(http.Controller):
visible_attrs = set(l.attribute_id.id
for l in product.attribute_line_ids
if len(l.value_ids) > 1)
if request.website.pricelist_id.id != context['pricelist']:
website_currency_id = request.website.currency_id.id
currency_id = self.get_pricelist().currency_id.id
if request.website.currency_id != product.currency_id:
for p in product.product_variant_ids:
price = currency_obj.compute(cr, uid, website_currency_id, currency_id, p.lst_price)
price = currency_obj.compute(cr, uid, product.currency_id.id, request.website.currency_id.id, p.lst_price)
attribute_value_ids.append([p.id, [v.id for v in p.attribute_value_ids if v.attribute_id.id in visible_attrs], p.price, price])
else:
attribute_value_ids = [[p.id, [v.id for v in p.attribute_value_ids if v.attribute_id.id in visible_attrs], p.price, p.lst_price]
for p in product.product_variant_ids]
return attribute_value_ids
@http.route(['/shop/change_pricelist/<model("product.pricelist"):pl_id>'], type='http', auth="public", website=True)
@@ -1051,9 +1048,6 @@ class website_sale(http.Controller):
cr, uid, context, pool = request.cr, request.uid, request.context, request.registry
products = pool['product.product'].browse(cr, uid, product_ids, context=context)
partner = pool['res.users'].browse(cr, uid, uid, context=context).partner_id
if use_order_pricelist:
pricelist_id = request.website.get_current_pricelist(context=context).id
else:
pricelist_id = partner.property_product_pricelist.id
pricelist_id = request.website.get_current_pricelist(context=context).id
prices = pool['product.pricelist'].price_rule_get_multi(cr, uid, [pricelist_id], [(product, add_qty, partner) for product in products], context=context)
return {product_id: prices[product_id][pricelist_id][0] for product_id in product_ids}
+7 -7
View File
@@ -92,7 +92,7 @@
<t t-if="(compute_currency(product.lst_price) - product.price) &gt; 0.1">
<del class="text-danger mr8" style="white-space: nowrap;" t-field="product.lst_price" t-field-options='{
"widget": "monetary",
"from_currency": "product.company_id.currency_id",
"from_currency": "product.currency_id",
"display_currency": "website.currency_id"
}'/>
</t>
@@ -422,7 +422,7 @@
t-field="product.lst_price"
t-field-options='{
"widget": "monetary",
"from_currency": "product.company_id.currency_id",
"from_currency": "product.currency_id",
"display_currency": "website.currency_id"
}'/>
<b class="oe_price" style="white-space: nowrap;"
@@ -438,7 +438,7 @@
<span t-field="product.lst_price"
t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
"display_currency": "product.currency_id"
}'/>
</h4>
<h4 class="hidden oe_not_available bg-warning">Product not available</h4>
@@ -458,7 +458,7 @@
<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.company_id.currency_id",
"from_currency": "product.currency_id",
"display_currency": "website.currency_id"
}'/>
</span>
@@ -483,7 +483,7 @@
<span t-if="value_id.price_extra">
<t t-esc="value_id.price_extra > 0 and '+' or ''"/><span t-field="value_id.price_extra" style="white-space: nowrap;" t-field-options='{
"widget": "monetary",
"from_currency": "product.company_id.currency_id",
"from_currency": "product.currency_id",
"display_currency": "website.currency_id"
}'/>
</span>
@@ -503,7 +503,7 @@
<span class="badge" t-if="value_id.price_extra">
<t t-esc="value_id.price_extra > 0 and '+' or ''"/><span t-field="value_id.price_extra" style="white-space: nowrap;" t-field-options='{
"widget": "monetary",
"from_currency": "product.company_id.currency_id",
"from_currency": "product.currency_id",
"display_currency": "website.currency_id"
}'/>
</span>
@@ -899,7 +899,7 @@
<del class="text-danger mr8" style="white-space: nowrap;"
t-field="product.lst_price" t-field-options='{
"widget": "monetary",
"from_currency": "product.company_id.currency_id",
"from_currency": "product.currency_id",
"display_currency": "website.currency_id"
}'/>
</t>
@@ -59,16 +59,15 @@
t-field="product.lst_price"
t-field-options='{
"widget": "monetary",
"from_currency": "product.company_id.currency_id",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
"from_currency": "product.currency_id",
"display_currency": "website.currency_id"
}'/>
<span class="oe_price" style="white-space: nowrap;"
t-att-data-product-id="product.id"
t-field="product.price"
t-field-options='{
"widget": "monetary",
"from_currency": "product.company_id.currency_id",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
"display_currency": "website.currency_id"
}'/>
</td>
<td>
@@ -107,14 +106,14 @@
t-field="product.lst_price"
t-field-options='{
"widget": "monetary",
"from_currency": "product.company_id.currency_id",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
"from_currency": "product.currency_id",
"display_currency": "website.currency_id"
}'/><br/>
<span class="oe_price" style="white-space: nowrap;"
t-field="product.price"
t-field-options='{
"widget": "monetary",
"display_currency": "user_id.partner_id.property_product_pricelist.currency_id"
"display_currency": "website.currency_id"
}'/>
<p class="css_not_available_msg bg-danger" style="position:absolute; padding: 15px;">Product not available</p>
</td>