From e67dc74a855386fc02b850b4fef10cc9e9ee8701 Mon Sep 17 00:00:00 2001 From: Bertrand Chenal Date: Thu, 10 Jul 2008 11:25:52 +0200 Subject: [PATCH] Don't try ot find rate when converting amount to the same currency --- currency.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/currency.py b/currency.py index 3ad1e17000..aa25425d2e 100644 --- a/currency.py +++ b/currency.py @@ -98,6 +98,11 @@ class Currency(OSV): from_currency = self.browse(cursor, user, from_currency, context=context) if isinstance(to_currency, (int, long)): to_currency = self.browse(cursor, user, to_currency, context=context) + if to_currency == from_currency: + if round: + return self.round(cursor, user, to_currency, amount) + else: + return amount if (not from_currency.rate) or (not to_currency.rate): date = context.get('date', time.strftime('%Y-%m-%d')) if not from_currency.rate: @@ -107,17 +112,11 @@ class Currency(OSV): raise ExceptOSV('UserError', 'No rate found \n' \ 'for the currency: %s \n' \ 'at the date: %s' % (name, date)) - if to_currency == from_currency: - if round: - return self.round(cursor, user, to_currency, amount) - else: - return amount + if round: + return self.round(cursor, user, to_currency, + amount * to_currency.rate / from_currency.rate) else: - if round: - return self.round(cursor, user, to_currency, - amount * to_currency.rate / from_currency.rate) - else: - return amount * to_currency.rate / from_currency.rate + return amount * to_currency.rate / from_currency.rate Currency()