From 765e5bb5fce715f5fcbe85448a310f57ee9fc3ec Mon Sep 17 00:00:00 2001 From: mtr Date: Fri, 1 Jul 2011 17:03:11 +0530 Subject: [PATCH] [IMP] sale_margin: improved code to check the condition before calculating the Cost Price bzr revid: mtr@mtr-20110701113311-3jdav34yu1s3cd02 --- addons/sale_margin/sale_margin.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/sale_margin/sale_margin.py b/addons/sale_margin/sale_margin.py index 28e0d66..e38eb61 100644 --- a/addons/sale_margin/sale_margin.py +++ b/addons/sale_margin/sale_margin.py @@ -30,11 +30,12 @@ class sale_order_line(osv.osv): 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) frm_cur = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id.id - 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}) + 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}) return res def _product_margin(self, cr, uid, ids, field_name, arg, context=None): -- 1.7.10.4