From 78545ce0edf73dffc27a0923e12240bddfdcee64 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Mon, 17 Feb 2020 16:41:00 +0000 Subject: [PATCH] [FIX] web: digits option for aggregate is taken into account MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you have a currency with 3 decimals, when you show a list view grouped, you might have result like: [group partner 1 : amount : 4.4€] - amount : 1.11€ - amount : 3.33€ which is a little odd, it is not that odd since the groupings are an approximation (eg. you could have a line in EUR and a line in USD and the grouping value would be the sum of both line). But there is no way to specify another precision, and since this is a grouping it could be of line of different currencies so we can't use the lines currency to decide. With this changeset, having for example: with `digits` attribute is taken into account for the aggregate value and it would be displayed with 3 decimals. Without the fix, the added test fails with: aggregates monetary use digits attribute if available Expected: "2000.000", Result: "2000.00" opw-2195042 closes #45545 closes odoo/odoo#46094 X-original-commit: 4dd293c71851d0c6e9ffe09402cf54cfe889f402 Signed-off-by: Nicolas Lempereur (nle) --- .../static/src/js/views/list/list_renderer.js | 5 ++++- addons/web/static/tests/views/list_tests.js | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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 c3581cb1564..cf47c997597 100644 --- a/addons/web/static/src/js/views/list/list_renderer.js +++ b/addons/web/static/src/js/views/list/list_renderer.js @@ -352,7 +352,10 @@ var ListRenderer = BasicRenderer.extend({ if (!formatFunc) { formatFunc = field_utils.format[field.type]; } - var formattedValue = formatFunc(value, field, { escape: true }); + var formattedValue = formatFunc(value, field, { + escape: true, + digits: column.attrs.digits ? JSON.parse(column.attrs.digits) : undefined, + }); $cell.addClass('o_list_number').attr('title', help).html(formattedValue); } return $cell; diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index cd33debf27d..6e2297be1c2 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -1412,6 +1412,26 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('aggregates digits can be set with digits field attribute', async function (assert) { + assert.expect(2); + + var list = await createView({ + View: ListView, + model: 'foo', + data: this.data, + arch: '' + + '' + + '', + }); + + assert.strictEqual(list.$('.o_data_row td:nth(1)').text(), '1200.00', + "field should still be formatted based on currency"); + assert.strictEqual(list.$('tfoot td:nth(1)').text(), '2000.000', + "aggregates monetary use digits attribute if available"); + + list.destroy(); + }); + QUnit.test('groups can be sorted on aggregates', async function (assert) { assert.expect(10); var list = await createView({