[IMP] sale_margin: improved code for checking the condition
authormtr <mtr@mtr>
Fri, 1 Jul 2011 11:56:21 +0000 (17:26 +0530)
committermtr <mtr@mtr>
Fri, 1 Jul 2011 11:56:21 +0000 (17:26 +0530)
bzr revid: mtr@mtr-20110701115621-2nc8uu9gxitdrcok

addons/sale_margin/sale_margin.py

index e38eb61..888efd4 100644 (file)
@@ -29,13 +29,14 @@ class sale_order_line(osv.osv):
         res = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty=qty,
             uom=uom, qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id,
             lang=lang, update_tax=update_tax, date_order=date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag)
+        if not pricelist:
+            return res
         frm_cur = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id
-        if pricelist:
-            to_cur = self.pool.get('product.pricelist').browse(cr, uid, [pricelist])[0].currency_id.id
-            if product:
-                purchase_price = self.pool.get('product.product').browse(cr, uid, product).standard_price
-                price = self.pool.get('res.currency').compute(cr, uid, frm_cur, to_cur, purchase_price, round=False)
-                res['value'].update({'purchase_price': price})
+        to_cur = self.pool.get('product.pricelist').browse(cr, uid, [pricelist])[0].currency_id.id
+        if product:
+            purchase_price = self.pool.get('product.product').browse(cr, uid, product).standard_price
+            price = self.pool.get('res.currency').compute(cr, uid, frm_cur, to_cur, purchase_price, round=False)
+            res['value'].update({'purchase_price': price})
         return res
 
     def _product_margin(self, cr, uid, ids, field_name, arg, context=None):