diff --git a/addons/web/static/src/legacy/js/views/list/list_renderer.js b/addons/web/static/src/legacy/js/views/list/list_renderer.js index 6e9647e6ac7..f648e21880c 100644 --- a/addons/web/static/src/legacy/js/views/list/list_renderer.js +++ b/addons/web/static/src/legacy/js/views/list/list_renderer.js @@ -176,8 +176,11 @@ var ListRenderer = BasicRenderer.extend({ aggregateValue = Infinity; } _.each(data, function (d) { - count += 1; var value = (d.type === 'record') ? d.data[attrs.name] : d.aggregateValues[attrs.name]; + if (Number(value) !== value) { + return; + } + count += 1; if (func === 'avg') { aggregateValue += value; } else if (func === 'sum') { @@ -191,10 +194,14 @@ var ListRenderer = BasicRenderer.extend({ if (func === 'avg') { aggregateValue = count ? aggregateValue / count : aggregateValue; } - column.aggregate = { - help: attrs[func], - value: aggregateValue, - }; + if (count) { + column.aggregate = { + help: attrs[func], + value: aggregateValue, + }; + } else { + delete column.aggregate; + } } }, /** diff --git a/addons/web/static/tests/legacy/views/list_tests.js b/addons/web/static/tests/legacy/views/list_tests.js index f3c763a0ab2..1dfb107d356 100644 --- a/addons/web/static/tests/legacy/views/list_tests.js +++ b/addons/web/static/tests/legacy/views/list_tests.js @@ -2405,7 +2405,7 @@ QUnit.module('Views', { // Let's update the view to dislay NO records await list.update({domain: ['&', ['bar', '=', false], ['int_field', '>', 0]]}); - assert.strictEqual(list.$('tfoot td:nth(2)').text(), "0", "total should have been recomputed to 0"); + assert.strictEqual(list.$('tfoot td:nth(2)').text(), "", "No records, so no total."); list.destroy(); }); @@ -2438,6 +2438,34 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('hide aggregated value in grouped lists when no data provided by RPC call', async function(assert) { + assert.expect(1); + + var list = await createView({ + View: ListView, + model: 'foo', + data: this.data, + groupBy: ['bar'], + arch: '', + mockRPC: function (route, args) { + return this._super.apply(this, arguments).then(result => { + // On PY-side, a read_group won't provide any aggregate value + // if the field does not have a `group_operator` attribute. + // (see 5691b126f06/odoo/models.py#L2521-L2528) + // Here, since `qux` does not have such an attribute, we + // remove the value provided by `_mockReadGroup` + _.each(result.groups, function(group) { + delete group.qux + }) + return Promise.resolve(result) + }); + }, + }); + + assert.strictEqual(list.$('tfoot td:nth(2)').text(), "", "There isn't any aggregated value"); + list.destroy(); + }) + QUnit.test('aggregates are updated when a line is edited', async function (assert) { assert.expect(2);