From 77fa521db55bca297955a2781daef513eeac894c Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Mon, 2 Dec 2013 14:12:44 +0530 Subject: [PATCH 1/8] [IMP] improve warning message bzr revid: bde@tinyerp.com-20131202084244-oc0gs75vwix3wgv3 --- openerp/addons/base/res/res_currency.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openerp/addons/base/res/res_currency.py b/openerp/addons/base/res/res_currency.py index 94a5f538b25..9b638c706a4 100644 --- a/openerp/addons/base/res/res_currency.py +++ b/openerp/addons/base/res/res_currency.py @@ -49,6 +49,7 @@ 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)) if cr.rowcount: @@ -57,7 +58,7 @@ class res_currency(osv.osv): elif not raise_on_no_rate: res[id] = 0 else: - raise osv.except_osv(_('Error!'),_("No currency rate associated for currency %d for the given period" % (id))) + raise osv.except_osv(_('Error!'),_("No currency rate associated for currency %d for the given period" % (currency_name))) return res _name = "res.currency" From ead427265235d06894edcedc8fc78c71a90f0d5f Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Mon, 2 Dec 2013 14:28:33 +0530 Subject: [PATCH 2/8] [IMP] improved the code bzr revid: bde@tinyerp.com-20131202085833-sp33bs3syiqaybsg --- openerp/addons/base/res/res_currency.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/addons/base/res/res_currency.py b/openerp/addons/base/res/res_currency.py index 9b638c706a4..558f7d98770 100644 --- a/openerp/addons/base/res/res_currency.py +++ b/openerp/addons/base/res/res_currency.py @@ -58,7 +58,7 @@ class res_currency(osv.osv): elif not raise_on_no_rate: res[id] = 0 else: - raise osv.except_osv(_('Error!'),_("No currency rate associated for currency %d 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" From 953c8d7633d2d516e00f048f788e3347f903c33e Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Mon, 2 Dec 2013 14:29:30 +0530 Subject: [PATCH 3/8] [IMP] improved the code bzr revid: bde@tinyerp.com-20131202085930-zinqv4q332iuqql0 --- openerp/addons/base/res/res_currency.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/addons/base/res/res_currency.py b/openerp/addons/base/res/res_currency.py index 558f7d98770..b8c0e1378ad 100644 --- a/openerp/addons/base/res/res_currency.py +++ b/openerp/addons/base/res/res_currency.py @@ -58,7 +58,7 @@ class res_currency(osv.osv): elif not raise_on_no_rate: res[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" 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 4/8] [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" From e2410358cd28cdf3e9e3a157ece9f7d367c6008f Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Wed, 12 Feb 2014 15:42:45 +0530 Subject: [PATCH 5/8] [IMP] improved bzr revid: bde@tinyerp.com-20140212101245-bhp1ncpuvckvex4m --- openerp/addons/base/res/res_currency.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openerp/addons/base/res/res_currency.py b/openerp/addons/base/res/res_currency.py index 931666f3d7f..0a50631f50b 100644 --- a/openerp/addons/base/res/res_currency.py +++ b/openerp/addons/base/res/res_currency.py @@ -56,9 +56,9 @@ class res_currency(osv.osv): if cr.rowcount: res[id] = cr.fetchone()[0] elif not raise_on_no_rate: - res[currency.id] = 0 + res[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 '%d' for the given period" % (id))) return res _name = "res.currency" From 7a672f0bb5dd2e4cbb400b3a8db2733be250686b Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Wed, 12 Feb 2014 15:43:34 +0530 Subject: [PATCH 6/8] [IMP] improved bzr revid: bde@tinyerp.com-20140212101334-mdhimtwrjn98d6g6 --- openerp/addons/base/res/res_currency.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/addons/base/res/res_currency.py b/openerp/addons/base/res/res_currency.py index 0a50631f50b..1419cc7ccb4 100644 --- a/openerp/addons/base/res/res_currency.py +++ b/openerp/addons/base/res/res_currency.py @@ -58,7 +58,7 @@ class res_currency(osv.osv): elif not raise_on_no_rate: res[id] = 0 else: - raise osv.except_osv(_('Error!'),_("No currency rate associated for currency '%d' for the given period" % (id))) + raise osv.except_osv(_('Error!'),_("No currency rate associated for currency %d for the given period" % (id))) return res _name = "res.currency" From b0c17397df7b3255a4bc9e500c9837f9fc82696e Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Wed, 12 Feb 2014 17:16:11 +0530 Subject: [PATCH 7/8] [IMP] improved the code to get the name of currency instead of id bzr revid: bde@tinyerp.com-20140212114611-et0fw2dlwwjuq39p --- openerp/addons/base/res/res_currency.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openerp/addons/base/res/res_currency.py b/openerp/addons/base/res/res_currency.py index 1419cc7ccb4..b62ed300439 100644 --- a/openerp/addons/base/res/res_currency.py +++ b/openerp/addons/base/res/res_currency.py @@ -46,19 +46,19 @@ 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' - for id in ids: + for currency in self.browse(cr, uid, ids, context=context): cr.execute('SELECT 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)) + (currency.id, date, currency_rate_type)) if cr.rowcount: - res[id] = cr.fetchone()[0] + res[currency.id] = cr.fetchone()[0] 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 %d for the given period" % (id))) + raise osv.except_osv(_('Error!'),_("No currency rate associated for currency '%s' for the given period" % (currency.name))) return res _name = "res.currency" From 22df13f4fd94f99b51d335ad58e3d1907e238de6 Mon Sep 17 00:00:00 2001 From: "Richard Mathot (OpenERP)" Date: Wed, 23 Apr 2014 09:35:11 +0200 Subject: [PATCH 8/8] [FIX] res_currency: Removing unnecessary 'browse' bzr revid: rim@openerp.com-20140423073511-kkjkt0a0baxz3466 --- openerp/addons/base/res/res_currency.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/openerp/addons/base/res/res_currency.py b/openerp/addons/base/res/res_currency.py index b62ed300439..19444786935 100644 --- a/openerp/addons/base/res/res_currency.py +++ b/openerp/addons/base/res/res_currency.py @@ -46,18 +46,19 @@ 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' - for currency in self.browse(cr, uid, ids, context=context): + for id in ids: cr.execute('SELECT 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)) + (id, date, currency_rate_type)) if cr.rowcount: - res[currency.id] = cr.fetchone()[0] + res[id] = cr.fetchone()[0] elif not raise_on_no_rate: - res[currency.id] = 0 + res[id] = 0 else: + currency = self.browse(cr, uid, id, context=context) raise osv.except_osv(_('Error!'),_("No currency rate associated for currency '%s' for the given period" % (currency.name))) return res