From 32dec19ee0bcb01091b747afe24a9a77026e9f29 Mon Sep 17 00:00:00 2001 From: kais-odoo Date: Thu, 27 Jul 2023 06:04:47 +0000 Subject: [PATCH] [FIX] web,project: fixes groupby attribute in pivot _getEmptyGroupLabel Before this commit, since we used to show custom label for project and assignees as 'private' and 'unassigned' section in pivot view, if we want to display show custom label for groupby with sub group type we might get confuse with passing 'groupby' attribute on _getEmptyGroupLabel pivot method. In this commit, fixes groupby issue by passing 'fieldname' instead of 'groupby' cause groupby contains 'groupname : subgroup' like 'deadline : year'. closes odoo/odoo#130960 Task: 3186578 X-original-commit: cae3531deb032289f5f823df7ffa565ee89189ea Signed-off-by: Xavier Bol (xbo) --- .../tests/project_task_groupby_tests.js | 139 ++++++++++++++++++ .../web/static/src/views/pivot/pivot_model.js | 2 +- 2 files changed, 140 insertions(+), 1 deletion(-) diff --git a/addons/project/static/tests/project_task_groupby_tests.js b/addons/project/static/tests/project_task_groupby_tests.js index 8ae0f747b88..059792c78d1 100644 --- a/addons/project/static/tests/project_task_groupby_tests.js +++ b/addons/project/static/tests/project_task_groupby_tests.js @@ -18,11 +18,23 @@ QUnit.module("Project", (hooks) => { type: "many2one", relation: "project.project", }, + user_ids: { + string: "Assignees", + type: "many2many", + relation: "project.task", + }, + date_deadline: { + string: "Deadline", + type: "date", + } }, records: [{ id: 1, display_name: "My task", project_id: false, + user_ids: [], + date_deadline: false, + }], }; target = getFixture(); @@ -47,6 +59,43 @@ QUnit.module("Project", (hooks) => { assert.strictEqual(target.querySelector(".o_group_name").innerText, "🔒 Private (1)"); }); + QUnit.test("Test group label for empty assignees in tree", async function (assert) { + assert.expect(1); + + const views = { + "project.task,false,list": + ``, + }; + const { openView } = await start({ + serverData: { views }, + }); + await openView({ + res_model: "project.task", + views: [[false, "tree"]], + context: { group_by: ["user_ids"] }, + }); + + assert.strictEqual(target.querySelector(".o_group_name").innerText, "👤 Unassigned (1)"); + }); + + QUnit.test("Test group label for empty deadline in tree", async function (assert) { + assert.expect(1); + + const views = { + "project.task,false,list": + ``, + }; + const { openView } = await start({ + serverData: { views }, + }); + await openView({ + res_model: "project.task", + views: [[false, "tree"]], + context: { group_by: ["date_deadline"] }, + }); + + assert.strictEqual(target.querySelector(".o_group_name").innerText, "None (1)"); + }); QUnit.test("Test group label for empty project in kanban", async function (assert) { assert.expect(1); @@ -70,6 +119,50 @@ QUnit.module("Project", (hooks) => { assert.strictEqual(target.querySelector(".o_column_title").innerText, "🔒 Private\n1"); }); + QUnit.test("Test group label for empty assignees in kanban", async function (assert) { + assert.expect(1); + + const views = { + "project.task,false,kanban": + ` + + + + `, + }; + const { openView } = await start({ + serverData: { views }, + }); + await openView({ + res_model: "project.task", + views: [[false, "kanban"]], + }); + + assert.strictEqual(target.querySelector(".o_column_title").innerText, "👤 Unassigned\n1"); + }); + + QUnit.test("Test group label for empty deadline in kanban", async function (assert) { + assert.expect(1); + + const views = { + "project.task,false,kanban": + ` + + + + `, + }; + const { openView } = await start({ + serverData: { views }, + }); + await openView({ + res_model: "project.task", + views: [[false, "kanban"]], + }); + + assert.strictEqual(target.querySelector(".o_column_title").innerText, "None"); + }); + QUnit.test("Test group label for empty project in pivot", async function (assert) { assert.expect(1); @@ -92,4 +185,50 @@ QUnit.module("Project", (hooks) => { "Private", ); }); + + QUnit.test("Test group label for empty assignees in pivot", async function (assert) { + assert.expect(1); + + const views = { + "project.task,false,pivot": + ` + + `, + }; + const { openView } = await start({ + serverData: { views }, + }); + await openView({ + res_model: "project.task", + views: [[false, "pivot"]], + }); + + assert.strictEqual( + target.querySelector("tr:nth-of-type(2) .o_pivot_header_cell_closed").innerText, + "Unassigned", + ); + }); + + QUnit.test("Test group label for empty deadline in pivot", async function (assert) { + assert.expect(1); + + const views = { + "project.task,false,pivot": + ` + + `, + }; + const { openView } = await start({ + serverData: { views }, + }); + await openView({ + res_model: "project.task", + views: [[false, "pivot"]], + }); + + assert.strictEqual( + target.querySelector("tr:nth-of-type(2) .o_pivot_header_cell_closed").innerText, + "None", + ); + }); }); diff --git a/addons/web/static/src/views/pivot/pivot_model.js b/addons/web/static/src/views/pivot/pivot_model.js index 401178f09de..29e0f94b8e8 100644 --- a/addons/web/static/src/views/pivot/pivot_model.js +++ b/addons/web/static/src/views/pivot/pivot_model.js @@ -1554,7 +1554,7 @@ export class PivotModel extends Model { : this.env._t("No"); } if (value === false) { - return this._getEmptyGroupLabel(groupBy); + return this._getEmptyGroupLabel(fieldName); } if (value instanceof Array) { return this._getNumberedLabel(value, fieldName, config);