From 2a8182a07fc5480c1e355c387fdf6354458afd05 Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Tue, 3 Dec 2013 14:50:56 +0530 Subject: [PATCH] [IMP] improved the code bzr revid: bde@tinyerp.com-20131203092056-l6c8x116iwv9oax6 --- openerp/addons/base/res/res_currency.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/openerp/addons/base/res/res_currency.py b/openerp/addons/base/res/res_currency.py index b8c0e1378ad..e53a1e87842 100644 --- a/openerp/addons/base/res/res_currency.py +++ b/openerp/addons/base/res/res_currency.py @@ -49,16 +49,15 @@ class res_currency(osv.osv): currency_rate_type = context.get('currency_rate_type_id') or None # ... and use 'is NULL' instead of '= some-id'. operator = '=' if currency_rate_type else 'is' - currency_name = self.browse(cr, uid, ids, context=context)[0].name - for id in ids: - cr.execute("SELECT currency_id, rate FROM res_currency_rate WHERE currency_id = %s AND name <= %s AND currency_rate_type_id " + operator +" %s ORDER BY name desc LIMIT 1" ,(id, date, currency_rate_type)) + for currency in self.browse(cr, uid, ids, context=context): + cr.execute("SELECT currency_id, rate FROM res_currency_rate WHERE currency_id = %s AND name <= %s AND currency_rate_type_id " + operator +" %s ORDER BY name desc LIMIT 1" ,(currency.id, date, currency_rate_type)) if cr.rowcount: id, rate = cr.fetchall()[0] res[id] = rate elif not raise_on_no_rate: - res[id] = 0 + res[currency.id] = 0 else: - raise osv.except_osv(_('Error!'),_("No currency rate associated for currency '%s' for the given period" % (currency_name))) + raise osv.except_osv(_('Error!'),_("No currency rate associated for currency '%s' for the given period" % (currency.name))) return res _name = "res.currency"