[FIX] base: Fixed currency rate argument problem in context.

bzr revid: uco@tinyerp.com-20110824091022-0n1iwkefv2h4nh74
This commit is contained in:
Ujjvala Collins (OpenERP) 2011-08-24 14:40:22 +05:30
parent 108db379d0
commit 2ef8385544
1 changed files with 21 additions and 11 deletions

View File

@ -103,41 +103,51 @@ class res_currency(osv.osv):
def is_zero(self, cr, uid, currency, amount):
return abs(self.round(cr, uid, currency, amount)) < currency.rounding
def _get_conversion_rate(self, cr, uid, from_currency, to_currency, context=None):
def _get_conversion_rate(self, cr, uid, from_currency_rate, to_currency_rate, context=None):
if context is None:
context = {}
if from_currency['rate'] == 0 or to_currency['rate'] == 0:
if from_currency_rate == 0 or to_currency_rate == 0:
date = context.get('date', time.strftime('%Y-%m-%d'))
if from_currency['rate'] == 0:
currency_symbol = from_currency.symbol
if from_currency_rate == 0:
currency_symbol = context.get('from_curr_symbol')
else:
currency_symbol = to_currency.symbol
currency_symbol = context.get('to_curr_symbol')
raise osv.except_osv(_('Error'), _('No rate found \n' \
'for the currency: %s \n' \
'at the date: %s') % (currency_symbol, date))
return to_currency.rate/from_currency.rate
return to_currency_rate/from_currency_rate
def compute(self, cr, uid, from_currency_id, to_currency_id, from_amount,
round=True, currency_rate_type_from=False, currency_rate_type_to=False, context=None):
if not context:
context = {}
if not from_currency_id:
from_currency_id = to_currency_id
if not to_currency_id:
to_currency_id = from_currency_id
context.update({'currency_rate_type_id': currency_rate_type_from})
xc = self.browse(cr, uid, [from_currency_id], context=context)
context.update({'currency_rate_type_id': currency_rate_type_to})
xc1 = self.browse(cr, uid, [to_currency_id], context=context)
ctx1 = context.copy()
ctx1.update({'currency_rate_type_id': currency_rate_type_from})
xc = self.browse(cr, uid, [from_currency_id], context=ctx1)
from_currency = (xc[0].id == from_currency_id and xc[0]) or xc[1]
from_currency_rate = from_currency['rate']
context.update({'from_curr_symbol': from_currency.symbol})
ctx2 = context.copy()
ctx2.update({'currency_rate_type_id': currency_rate_type_to})
xc1 = self.browse(cr, uid, [to_currency_id], context=ctx2)
to_currency = (xc1[0].id == to_currency_id and xc1[0]) or xc1[1]
to_currency_rate = to_currency['rate']
context.update({'to_curr_symbol': to_currency.symbol})
if to_currency_id == from_currency_id:
if round:
return self.round(cr, uid, to_currency, from_amount)
else:
return from_amount
else:
rate = self._get_conversion_rate(cr, uid, from_currency, to_currency, context=context)
rate = self._get_conversion_rate(cr, uid, from_currency_rate, to_currency_rate, context=context)
if round:
return self.round(cr, uid, to_currency, from_amount * rate)
else: