[FIX] product_visible_discount: multicurrency pricelists
authorMartin Trigaux <mat@openerp.com>
Fri, 1 Aug 2014 10:43:31 +0000 (12:43 +0200)
committerMartin Trigaux <mat@openerp.com>
Fri, 1 Aug 2014 13:48:24 +0000 (15:48 +0200)
When we compute the discount of a product to display (result of product_id_change), we compare prices in the currency of the product while we expect prices in the currency of the pricelist. opw 606188

addons/product_visible_discount/product_visible_discount.py

index b8a6e45..275bfcd 100644 (file)
@@ -84,10 +84,15 @@ class sale_order_line(osv.osv):
             list_price = pricelist_obj.price_get(cr, uid, [pricelist],
                     product.id, qty or 1.0, partner_id, {'uom': uom,'date': date_order })
 
-            pricelists = pricelist_obj.read(cr,uid,[pricelist],['visible_discount'])
+            so_pricelist = pricelist_obj.browse(cr, uid, pricelist, context=context)
 
             new_list_price = get_real_price(list_price, product.id, qty, uom, pricelist)
-            if len(pricelists)>0 and pricelists[0]['visible_discount'] and list_price[pricelist] != 0 and new_list_price != 0:
+            if so_pricelist.visible_discount and list_price[pricelist] != 0 and new_list_price != 0:
+                if so_pricelist.currency_id.id != product.company_id.currency_id.id:
+                    # new_list_price is in company's currency while price in pricelist currency
+                    new_list_price = self.pool['res.currency'].compute(cr, uid,
+                        product.company_id.currency_id.id, so_pricelist.currency_id.id,
+                        new_list_price, context=context)
                 discount = (new_list_price - price) / new_list_price * 100
                 if discount > 0:
                     result['price_unit'] = new_list_price