From 36b0157f8b336cf9d43a953525eed60e7d679f75 Mon Sep 17 00:00:00 2001 From: Lionel <> Date: Mon, 6 Sep 2010 16:47:51 +0530 Subject: [PATCH] [FIX] Currency : better handling of context bzr revid: jvo@tinyerp.com-20100906111751-h4pdbgqa5bfzqtty --- bin/addons/base/res/res_currency.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/bin/addons/base/res/res_currency.py b/bin/addons/base/res/res_currency.py index 2cd7682be5b..1a233df4f19 100644 --- a/bin/addons/base/res/res_currency.py +++ b/bin/addons/base/res/res_currency.py @@ -27,20 +27,22 @@ from tools.misc import currency from tools.translate import _ class res_currency(osv.osv): - def _current_rate(self, cr, uid, ids, name, arg, context={}): - res={} + def _current_rate(self, cr, uid, ids, name, arg, context=None): + if context is None: + context = {} + res = {} if 'date' in context: - date=context['date'] + date = context['date'] else: - date=time.strftime('%Y-%m-%d') - date= date or time.strftime('%Y-%m-%d') + date = time.strftime('%Y-%m-%d') + date = date or time.strftime('%Y-%m-%d') for id in ids: cr.execute("SELECT currency_id, rate FROM res_currency_rate WHERE currency_id = %s AND name <= %s ORDER BY name desc LIMIT 1" ,(id, date)) if cr.rowcount: - id, rate=cr.fetchall()[0] - res[id]=rate + id, rate = cr.fetchall()[0] + res[id] = rate else: - res[id]=0 + res[id] = 0 return res _name = "res.currency" _description = "Currency" @@ -71,9 +73,9 @@ class res_currency(osv.osv): if r.__contains__('rate_ids'): rates=r['rate_ids'] if rates: - currency_rate_obj=self.pool.get('res.currency.rate') - currency_date=currency_rate_obj.read(cr,user,rates[0],['name'])['name'] - r['date']=currency_date + currency_rate_obj= self.pool.get('res.currency.rate') + currency_date = currency_rate_obj.read(cr,user,rates[0],['name'])['name'] + r['date'] = currency_date return res def round(self, cr, uid, currency, amount): @@ -87,7 +89,9 @@ class res_currency(osv.osv): def is_zero(self, cr, uid, currency, amount): return abs(self.round(cr, uid, currency, amount)) < currency.rounding - def compute(self, cr, uid, from_currency_id, to_currency_id, from_amount, round=True, context={}, account=None, account_invert=False): + def compute(self, cr, uid, from_currency_id, to_currency_id, from_amount, round=True, context=None, account=None, account_invert=False): + if context is None: + context = {} if not from_currency_id: from_currency_id = to_currency_id if not to_currency_id: