[IMP] smartenify res_currency code
bzr revid: xmo@openerp.com-20131011105120-1d5fg06j6zsuxty2
This commit is contained in:
parent
ef848653af
commit
9cbc632fa1
|
@ -40,20 +40,21 @@ class res_currency(osv.osv):
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
res = {}
|
res = {}
|
||||||
if 'date' in context:
|
|
||||||
date = context['date']
|
date = context.get('date') or time.strftime('%Y-%m-%d')
|
||||||
else:
|
|
||||||
date = time.strftime('%Y-%m-%d')
|
|
||||||
date = date or time.strftime('%Y-%m-%d')
|
|
||||||
# Convert False values to None ...
|
# Convert False values to None ...
|
||||||
currency_rate_type = context.get('currency_rate_type_id') or None
|
currency_rate_type = context.get('currency_rate_type_id') or None
|
||||||
# ... and use 'is NULL' instead of '= some-id'.
|
# ... and use 'is NULL' instead of '= some-id'.
|
||||||
operator = '=' if currency_rate_type else 'is'
|
operator = '=' if currency_rate_type else 'is'
|
||||||
for id in ids:
|
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))
|
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))
|
||||||
if cr.rowcount:
|
if cr.rowcount:
|
||||||
id, rate = cr.fetchall()[0]
|
res[id] = cr.fetchone()[0]
|
||||||
res[id] = rate
|
|
||||||
elif not raise_on_no_rate:
|
elif not raise_on_no_rate:
|
||||||
res[id] = 0
|
res[id] = 0
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue