From 857c4851754dcddf9e6dc7b39585914beaf89c88 Mon Sep 17 00:00:00 2001 From: Mitali Patel Date: Wed, 19 Jun 2019 10:21:23 +0000 Subject: [PATCH] [IMP] base/web: store more precision digits for rate field Currently, only 6 digits after decimal point is stored in database and for some currencies it may require to have more digits after decimal precision to correctly convert rates, like MXN -> USD currency. So, we allow maximum digits to be stored in database. On the view side, wherever rate is editable(form or tree view), we show 12 digits after decimal point and on list view, we truncate limit it to 6 digits. Also, a bug is fixed for web where 'digits' attribute for float field on list view isn't considered. Also, we have to remove a test case statement which only checks for 6 digits for a float number. task: 2024668 closes: #34279 Signed-off-by: Josse Colpaert --- .../web/static/src/js/views/list/list_renderer.js | 1 + addons/web/static/tests/views/list_tests.js | 13 +++++++++++++ odoo/addons/base/models/res_currency.py | 4 ++-- odoo/addons/base/tests/test_float.py | 3 +-- odoo/addons/base/views/res_currency_views.xml | 10 +++++----- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/addons/web/static/src/js/views/list/list_renderer.js b/addons/web/static/src/js/views/list/list_renderer.js index d4896276b90..845014926b3 100644 --- a/addons/web/static/src/js/views/list/list_renderer.js +++ b/addons/web/static/src/js/views/list/list_renderer.js @@ -405,6 +405,7 @@ var ListRenderer = BasicRenderer.extend({ data: record.data, escape: true, isPassword: 'password' in node.attrs, + digits: node.attrs.digits && JSON.parse(node.attrs.digits), }); this._handleAttributes($td, node); var title = field.type !== 'boolean' ? formattedValue : ''; diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 81de376aef0..55cec265329 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -6670,6 +6670,19 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('float field render with digits attribute on listview', async function (assert) { + assert.expect(1); + + var list = await createView({ + View: ListView, + model: 'foo', + data: this.data, + arch: '', + }); + + assert.strictEqual(list.$('td.o_list_number:eq(0)').text(), "0.400000", "should contain 6 digits decimal precision"); + list.destroy(); + }); // TODO: write test on: // - default_get with a field not in view }); diff --git a/odoo/addons/base/models/res_currency.py b/odoo/addons/base/models/res_currency.py index a7f25a2df0b..86099e3faee 100644 --- a/odoo/addons/base/models/res_currency.py +++ b/odoo/addons/base/models/res_currency.py @@ -28,7 +28,7 @@ class Currency(models.Model): # Note: 'code' column was removed as of v6.0, the 'name' should now hold the ISO code. name = fields.Char(string='Currency', size=3, required=True, help="Currency Code (ISO 4217)") symbol = fields.Char(help="Currency sign, to be used when printing amounts.", required=True) - rate = fields.Float(compute='_compute_current_rate', string='Current Rate', digits=(12, 6), + rate = fields.Float(compute='_compute_current_rate', string='Current Rate', digits=0, help='The rate of the currency to the currency of rate 1.') rate_ids = fields.One2many('res.currency.rate', 'currency_id', string='Rates') rounding = fields.Float(string='Rounding Factor', digits=(12, 6), default=0.01) @@ -235,7 +235,7 @@ class CurrencyRate(models.Model): name = fields.Date(string='Date', required=True, index=True, default=lambda self: fields.Date.today()) - rate = fields.Float(digits=(12, 6), default=1.0, help='The rate of the currency to the currency of rate 1') + rate = fields.Float(digits=0, default=1.0, help='The rate of the currency to the currency of rate 1') currency_id = fields.Many2one('res.currency', string='Currency', readonly=True) company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company) diff --git a/odoo/addons/base/tests/test_float.py b/odoo/addons/base/tests/test_float.py index 4dbf1f5f139..7ece1b0b8ce 100644 --- a/odoo/addons/base/tests/test_float.py +++ b/odoo/addons/base/tests/test_float.py @@ -172,8 +172,7 @@ class TestFloatPrecision(TransactionCase): self.assertEqual(rate.rate, expected, 'Roundtrip error: got %s back from db, expected %s' % (rate, expected)) - # res.currency.rate uses 6 digits of precision by default - try_roundtrip(2.6748955, 2.674896, '2000-01-01') + # res.currency.rate no more uses 6 digits of precision by default, it now uses whatever precision it gets try_roundtrip(10000.999999, 10000.999999, '2000-01-03') #TODO re-enable those tests when tests are made on dedicated models diff --git a/odoo/addons/base/views/res_currency_views.xml b/odoo/addons/base/views/res_currency_views.xml index 52bbcb71cb3..bb7c987160e 100644 --- a/odoo/addons/base/views/res_currency_views.xml +++ b/odoo/addons/base/views/res_currency_views.xml @@ -17,7 +17,7 @@ - + @@ -32,7 +32,7 @@ - + @@ -75,7 +75,7 @@ - + @@ -102,7 +102,7 @@
Current Rate: - +
@@ -125,7 +125,7 @@ - +