[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.
This commit is contained in:
Aaron Bohy
2018-02-12 11:11:43 +01:00
parent 0982ceaa37
commit 11dff2b05c
2 changed files with 24 additions and 3 deletions
@@ -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;
@@ -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: '<tree>' +
'<field name="foo"/>' +
'<field name="qux" widget="float_time" sum="Sum"/>' +
'</tree>',
});
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);