[FIX] product_visible_discount: discount with different unit of measures
authorMartin Trigaux <mat@odoo.com>
Fri, 24 Oct 2014 14:07:55 +0000 (16:07 +0200)
committerMartin Trigaux <mat@odoo.com>
Fri, 24 Oct 2014 15:21:42 +0000 (17:21 +0200)
The computation of the price without pricelist should take care of the unit of measure.
e.g. if computing discount for objects in dozen (on a product with price in unit), returned unit price should be (price*12) where 12 is the factor to go from dozen to unit.
Otherwise the compared prices (with and without pricelist) would not use the same unit of measure and the comparaison would be inconsistent. (opw 599727)

addons/product_visible_discount/product_visible_discount.py

index 595deba..f173e84 100644 (file)
@@ -44,6 +44,7 @@ class sale_order_line(osv.osv):
             fiscal_position=False, flag=False, context=None):
 
         def get_real_price(res_dict, product_id, qty, uom, pricelist):
+            """Retrieve the price before applying the pricelist"""
             item_obj = self.pool.get('product.pricelist.item')
             price_type_obj = self.pool.get('product.price.type')
             product_obj = self.pool.get('product.product')
@@ -60,9 +61,8 @@ class sale_order_line(osv.osv):
 
             factor = 1.0
             if uom and uom != product.uom_id.id:
-                product_uom_obj = self.pool.get('product.uom')
-                uom_data = product_uom_obj.browse(cr, uid,  product.uom_id.id)
-                factor = uom_data.factor
+                # the unit price is in a different uom
+                factor = self.pool['product.uom']._compute_qty(cr, uid, uom, 1.0, product.uom_id.id)
             return product_read[field_name] * factor