[FIX] web: pivot view: use correct label for headers

Before this revision, the pivot view used the wrong label for the
headers in the case of the group by value was "0". This was due to
the use of the falsy value of the group by value to determine if
the label should be used or if the label should be "Total".

closes odoo/odoo#112571

X-original-commit: 97db8c975643bb79e95f7506da03c7142651a3cf
Signed-off-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
This commit is contained in:
Pierre Rousseau
2023-02-13 20:13:04 +01:00
parent d837d0b4e2
commit ac6db52173
2 changed files with 50 additions and 2 deletions
@@ -1220,7 +1220,10 @@ export class PivotModel extends Model {
rowIndex === 0
? undefined
: fields[colGroupBys[rowIndex - 1].split(":")[0]].string,
title: group.labels[group.labels.length - 1] || _t("Total"),
title:
group.labels.length
? group.labels[group.labels.length - 1]
: _t("Total"),
width: leafCount * measureCount * (2 * originCount - 1),
};
row.push(cell);
@@ -1271,7 +1274,10 @@ export class PivotModel extends Model {
let rows = [];
const group = tree.root;
const rowGroupId = [group.values, []];
const title = group.labels[group.labels.length - 1] || this.env._t("Total");
const title =
group.labels.length
? group.labels[group.labels.length - 1]
: this.env._t("Total");
const indent = group.labels.length;
const isLeaf = !tree.directSubTrees.size;
const rowGroupBys = this.metaData.fullRowGroupBys;
@@ -279,6 +279,48 @@ QUnit.module("Views", (hooks) => {
);
});
QUnit.test("Pivot with integer row group by with 0 as header", async function (assert) {
serverData.models.partner.records[0].foo = 0;
serverData.models.partner.records[1].foo = 0;
serverData.models.partner.records[2].foo = 0;
serverData.models.partner.records[3].foo = 0;
const pivot = await makeView({
type: "pivot",
resModel: "partner",
serverData,
arch: `
<pivot string="Partners">
<field name="foo" type="measure"/>
<field name="foo" type="row"/>
</pivot>`,
});
const { rows } = pivot.model.getTable();
assert.strictEqual(rows.length, 2);
assert.strictEqual(rows[0].title, "Total");
assert.strictEqual(rows[1].title, 0);
});
QUnit.test("Pivot with integer col group by with 0 as header", async function (assert) {
serverData.models.partner.records[0].foo = 0;
serverData.models.partner.records[1].foo = 0;
serverData.models.partner.records[2].foo = 0;
serverData.models.partner.records[3].foo = 0;
const pivot = await makeView({
type: "pivot",
resModel: "partner",
serverData,
arch: `
<pivot string="Partners">
<field name="foo" type="measure"/>
<field name="foo" type="col"/>
</pivot>`,
});
const { headers } = pivot.model.getTable();
assert.strictEqual(headers[1][0].title, 0);
});
QUnit.test(
"pivot rendering with string attribute on non stored field",
async function (assert) {