From af174897abcb516f134930997fc30fcbf3d2ea41 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Fri, 4 Mar 2016 15:42:25 +0100 Subject: [PATCH] [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 --- addons/website_sale/controllers/main.py | 12 +++--------- addons/website_sale/views/templates.xml | 14 +++++++------- addons/website_sale_options/views/templates.xml | 13 ++++++------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index e71f56b7fa0..fbb338cba53 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -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/'], 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} diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml index 3dc01f720e8..cd4efc6a967 100644 --- a/addons/website_sale/views/templates.xml +++ b/addons/website_sale/views/templates.xml @@ -92,7 +92,7 @@ @@ -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" }'/> @@ -458,7 +458,7 @@ @@ -483,7 +483,7 @@ @@ -503,7 +503,7 @@ @@ -899,7 +899,7 @@ diff --git a/addons/website_sale_options/views/templates.xml b/addons/website_sale_options/views/templates.xml index 3f4f026d7db..b9aba78f23c 100644 --- a/addons/website_sale_options/views/templates.xml +++ b/addons/website_sale_options/views/templates.xml @@ -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" }'/> @@ -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" }'/>

Product not available