From 11dff2b05c72adb01f4094aa5077218a29315dec Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 12 Feb 2018 09:21:55 +0100 Subject: [PATCH] [FIX] web: ListView: format footer values Before this rev., the aggregates values displayed in the footer of list views were formatted according to the field type, and the field's widget was ignored, whereas it should be used by default. For instance, if the 'float_time' widget is set on a float field, the sum should be formatted as FloatTime as well. Closes #22724. --- .../static/src/js/views/list/list_renderer.js | 8 +++++--- addons/web/static/tests/views/list_tests.js | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 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 4c2eed53e18..32ff58acd02 100644 --- a/addons/web/static/src/js/views/list/list_renderer.js +++ b/addons/web/static/src/js/views/list/list_renderer.js @@ -204,9 +204,11 @@ var ListRenderer = BasicRenderer.extend({ var field = self.state.fields[column.attrs.name]; var value = aggregateValues[column.attrs.name].value; var help = aggregateValues[column.attrs.name].help; - var formattedValue = field_utils.format[field.type](value, field, { - escape: true, - }); + var formatFunc = field_utils.format[column.attrs.widget]; + if (!formatFunc) { + formatFunc = field_utils.format[field.type]; + } + var formattedValue = formatFunc(value, field, {escape: true}); $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 970a895719d..92ae4033562 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -694,6 +694,25 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('aggregates are formatted according to field widget', function (assert) { + assert.expect(1); + + var list = createView({ + View: ListView, + model: 'foo', + data: this.data, + arch: '' + + '' + + '' + + '', + }); + + assert.strictEqual(list.$('tfoot td:nth(2)').text(), '19:24', + "total should be formatted as a float_time"); + + list.destroy(); + }); + QUnit.test('groups can be sorted on aggregates', function (assert) { assert.expect(10);