[FIX] web: falsy group names in list view

When a group has a falsy value (e.g. if grouped by an integer field having a "0" group), make sure to display its proper name instead of "Undefined".
Off course, boolean fields are still showing "false" name if it is the case.

This issue was introduced with 3dd1c0f

closes odoo/odoo#76493

X-original-commit: 4e213f0b93f59cf377271b18eae9765ff9cfbe4f
Related: odoo/enterprise#20847
Signed-off-by: Mathieu Duckerts-Antoine <Polymorphe57@users.noreply.github.com>
This commit is contained in:
Bruno Boi
2021-09-14 15:10:15 +00:00
parent 6957a614d2
commit 3cd7ffdc6b
2 changed files with 37 additions and 7 deletions
@@ -714,11 +714,12 @@ var ListRenderer = BasicRenderer.extend({
_renderGroupRow: function (group, groupLevel) {
var cells = [];
var name = group.value === undefined ? _t('Undefined') : group.value;
var groupBy = this.state.groupedBy[groupLevel];
if (group.fields[groupBy.split(':')[0]].type !== 'boolean') {
name = name || _t('Undefined');
}
const groupBy = this.state.groupedBy[groupLevel];
const groupByFieldName = groupBy.split(':')[0];
const groupByField = group.fields[groupByFieldName];
const name = groupByField.type === "boolean"
? (group.value === undefined ? _t('Undefined') : group.value)
: (group.value === undefined || group.value === false ? _t('Undefined') : group.value);
var $th = $('<th>')
.addClass('o_group_name')
.attr('tabindex', -1)
@@ -9895,7 +9895,7 @@ QUnit.module('Views', {
});
QUnit.test('grouped lists with expand attribute and a lot of groups', async function (assert) {
assert.expect(8);
assert.expect(10);
for (var i = 0; i < 15; i++) {
this.data.foo.records.push({foo: 'record ' + i, int_field: i});
@@ -9916,14 +9916,43 @@ QUnit.module('Views', {
});
assert.containsN(list, '.o_group_header', 10); // page 1
assert.containsN(list, '.o_data_row', 11); // one group contains two records
assert.containsN(list, '.o_data_row', 12); // two groups contains two records
assert.containsOnce(list, '.o_pager'); // has a pager
assert.deepEqual(
[...list.el.querySelectorAll(".o_group_name")].map((el) => el.innerText),
[
"10 (2)",
"9 (2)",
"17 (1)",
"-4 (1)",
"0 (1)",
"1 (1)",
"2 (1)",
"3 (1)",
"4 (1)",
"5 (1)",
]
);
await cpHelpers.pagerNext(list); // switch to page 2
assert.containsN(list, '.o_group_header', 7); // page 2
assert.containsN(list, '.o_data_row', 7);
assert.deepEqual(
[...list.el.querySelectorAll(".o_group_name")].map((el) => el.innerText),
[
"6 (1)",
"7 (1)",
"8 (1)",
"11 (1)",
"12 (1)",
"13 (1)",
"14 (1)",
]
);
assert.verifySteps([
'web_read_group', // read_group page 1
'web_read_group', // read_group page 2