From 2b6033cc8c659e8be022df7881376ef83605db57 Mon Sep 17 00:00:00 2001 From: ced <> Date: Tue, 2 Jan 2007 08:19:17 +0000 Subject: [PATCH] INVOICE: use date for currency rate bzr revid: ced-9130e666782075780281565b106300b7dff82dab --- bin/addons/base/res/res_currency.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bin/addons/base/res/res_currency.py b/bin/addons/base/res/res_currency.py index 3c59527d5f9..ebea65b97ec 100644 --- a/bin/addons/base/res/res_currency.py +++ b/bin/addons/base/res/res_currency.py @@ -38,10 +38,14 @@ import mx.DateTime from mx.DateTime import RelativeDateTime, now, DateTime, localtime class res_currency(osv.osv): - def _current_rate(self, cr, uid, ids, name, arg, context): + def _current_rate(self, cr, uid, ids, name, arg, context={}): res={} + if 'date' in context: + date=context['date'] + else: + date=time.strftime('%Y-%m-%d') for id in ids: - cr.execute("SELECT currency_id, rate FROM res_currency_rate WHERE currency_id = %d AND name <= '%s' ORDER BY name desc LIMIT 1" % (id, time.strftime('%Y-%m-%d'))) + cr.execute("SELECT currency_id, rate FROM res_currency_rate WHERE currency_id = %d AND name <= '%s' ORDER BY name desc LIMIT 1" % (id, date)) if cr.rowcount: id, rate=cr.fetchall()[0] res[id]=rate @@ -67,11 +71,11 @@ class res_currency(osv.osv): def round(self, cr, uid, currency, amount): return round(amount / currency.rounding) * currency.rounding - def compute(self, cr, uid, from_currency_id, to_currency_id, from_amount, round=True): + def compute(self, cr, uid, from_currency_id, to_currency_id, from_amount, round=True, context={}): if to_currency_id==from_currency_id: return from_amount - from_currency=self.browse(cr, uid, [from_currency_id])[0] - to_currency = self.browse(cr, uid, [to_currency_id])[0] + from_currency=self.browse(cr, uid, [from_currency_id], context=context)[0] + to_currency = self.browse(cr, uid, [to_currency_id], context=context)[0] if from_currency['rate'] == 0 or to_currency['rate'] == 0: raise osv.except_osv('Error', 'No rate found for the currency') if round: