From d530e2edd8421929094726793b42d1288f0fd7bf Mon Sep 17 00:00:00 2001 From: ced <> Date: Tue, 7 Aug 2007 14:29:28 +0000 Subject: [PATCH] base: change currency rate definition bzr revid: ced-e582e4e8fb545a005be3ff6eb05d0f426e345966 --- bin/addons/base/res/res_currency.py | 10 ++++++---- doc/migrate/4.0.0-4.2.0/pre.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bin/addons/base/res/res_currency.py b/bin/addons/base/res/res_currency.py index 09eda1fca79..41b8de2f75e 100644 --- a/bin/addons/base/res/res_currency.py +++ b/bin/addons/base/res/res_currency.py @@ -57,7 +57,8 @@ class res_currency(osv.osv): _columns = { 'name': fields.char('Currency', size=32, required=True), 'code': fields.char('Code', size=3), - 'rate': fields.function(_current_rate, method=True, string='Current rate',digits=(12,6)), + 'rate': fields.function(_current_rate, method=True, string='Current rate', digits=(12,6), + help='The rate of the currency to the currency of rate 1'), 'rate_ids': fields.one2many('res.currency.rate', 'currency_id', 'Rates'), 'accuracy': fields.integer('Computational Accuracy'), 'rounding': fields.float('Rounding factor', digits=(12,6)), @@ -89,9 +90,9 @@ class res_currency(osv.osv): return from_amount else: if round: - return self.round(cr, uid, to_currency, from_amount * from_currency.rate/to_currency.rate) + return self.round(cr, uid, to_currency, from_amount * to_currency.rate/from_currency.rate) else: - return (from_amount * from_currency.rate/to_currency.rate) + return (from_amount * to_currency.rate/from_currency.rate) def name_search(self, cr, uid, name, args=[], operator='ilike', context={}, limit=80): args2 = args[:] if name: @@ -108,7 +109,8 @@ class res_currency_rate(osv.osv): _description = "Currency Rate" _columns = { 'name': fields.date('Date', required=True, select=True), - 'rate': fields.float('Rate', digits=(12,6), required=True), + 'rate': fields.float('Rate', digits=(12,6), required=True, + help='The rate of the currency to the currency of rate 1'), 'currency_id': fields.many2one('res.currency', 'Currency', readonly=True), } _defaults = { diff --git a/doc/migrate/4.0.0-4.2.0/pre.py b/doc/migrate/4.0.0-4.2.0/pre.py index b5dc76c1d88..24c38284b94 100644 --- a/doc/migrate/4.0.0-4.2.0/pre.py +++ b/doc/migrate/4.0.0-4.2.0/pre.py @@ -171,4 +171,15 @@ if not cr.fetchall(): cr.execute('INSERT INTO ir_values (name, key, model, meta, key2, object, value) VALUES (\'tz\', \'meta\', \'res.users\', %s, \'tz\', %s, %s)', (meta,False, value)) cr.commit() +# -------------------- # +# Change currency rate # +# -------------------- # + +cr.execute('SELECT a.attname FROM pg_class c, pg_attribute a WHERE c.relname = \'res_currency_rate\' AND a.attname = \'rate_old\' AND c.oid = a.attrelid') +if not cr.fetchall(): + cr.execute('ALTER TABLE res_currency_rate ADD rate_old NUMERIC(12,6)') + cr.execute('UPDATE res_currency_rate SET rate_old = rate') + cr.execute('UPDATE res_currency_rate SET rate = (1 / rate_old)') +cr.commit() + cr.close