From d11845e32232a73dbbdeffdf4743e71b245f2a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rahir=20=28rar=29?= Date: Thu, 2 Nov 2023 11:58:16 +0100 Subject: [PATCH] [IMP] spreadsheet: Improve ODOO.PIVOT.TABLE hook value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In order to identify an ODOO.PIVOT.TABLE formula cell, we set the display name of the pivot as the evaluated value of the cell containing the formula. closes odoo/odoo#140674 Task: 3580153 Related: odoo/enterprise#50003 Signed-off-by: Rémi Rahir (rar) --- addons/spreadsheet/static/src/pivot/index.js | 3 + .../static/src/pivot/pivot_functions.js | 2 +- .../pivots/model/pivot_table_function_test.js | 75 +++++++++++-------- 3 files changed, 47 insertions(+), 33 deletions(-) diff --git a/addons/spreadsheet/static/src/pivot/index.js b/addons/spreadsheet/static/src/pivot/index.js index cd27c5763ea..55247dfb363 100644 --- a/addons/spreadsheet/static/src/pivot/index.js +++ b/addons/spreadsheet/static/src/pivot/index.js @@ -32,14 +32,17 @@ coreTypes.add("UPDATE_ODOO_PIVOT_DOMAIN"); invalidateEvaluationCommands.add("UPDATE_ODOO_PIVOT_DOMAIN"); invalidateEvaluationCommands.add("REMOVE_PIVOT"); invalidateEvaluationCommands.add("INSERT_PIVOT"); +invalidateEvaluationCommands.add("RENAME_ODOO_PIVOT"); invalidateDependenciesCommands.add("UPDATE_ODOO_PIVOT_DOMAIN"); invalidateDependenciesCommands.add("REMOVE_PIVOT"); invalidateDependenciesCommands.add("INSERT_PIVOT"); +invalidateDependenciesCommands.add("RENAME_ODOO_PIVOT"); invalidateCFEvaluationCommands.add("UPDATE_ODOO_PIVOT_DOMAIN"); invalidateCFEvaluationCommands.add("REMOVE_PIVOT"); invalidateCFEvaluationCommands.add("INSERT_PIVOT"); +invalidateCFEvaluationCommands.add("RENAME_ODOO_PIVOT"); cellMenuRegistry.add("pivot_see_records", { name: _t("See records"), diff --git a/addons/spreadsheet/static/src/pivot/pivot_functions.js b/addons/spreadsheet/static/src/pivot/pivot_functions.js index a17a3fc0d04..b9138533a7d 100644 --- a/addons/spreadsheet/static/src/pivot/pivot_functions.js +++ b/addons/spreadsheet/static/src/pivot/pivot_functions.js @@ -187,7 +187,7 @@ const ODOO_PIVOT_TABLE = { const _includeColumnHeaders = toBoolean(includeColumnHeaders.value); const cells = table.getPivotCells(toBoolean(includeTotal.value), _includeColumnHeaders); const headerRows = _includeColumnHeaders ? table.getNumberOfHeaderRows() : 0; - const pivotTitle = _t("Pivot #%s", _pivotId); + const pivotTitle = this.getters.getPivotDisplayName(_pivotId); const _rowCount = toNumber(rowCount.value); if (_rowCount < 0) { throw new Error(_t("The number of rows must be positive.")); diff --git a/addons/spreadsheet/static/tests/pivots/model/pivot_table_function_test.js b/addons/spreadsheet/static/tests/pivots/model/pivot_table_function_test.js index 59065024fac..89acc72135e 100644 --- a/addons/spreadsheet/static/tests/pivots/model/pivot_table_function_test.js +++ b/addons/spreadsheet/static/tests/pivots/model/pivot_table_function_test.js @@ -24,7 +24,7 @@ QUnit.test("full ODOO.PIVOT.TABLE() values", async function (assert) { setCellContent(model, "A1", `=ODOO.PIVOT.TABLE("1")`, "42"); // prettier-ignore assert.deepEqual(getEvaluatedGrid(model, "A1:D7", "42"), [ - ["Pivot #1", "xphone", "xpad", "Total"], + ["(#1) Partner Pivot", "xphone", "xpad", "Total"], ["", "Probability", "Probability", "Probability"], [1, "", 11, 11], [2, "", 15, 15], @@ -52,10 +52,10 @@ QUnit.test("ODOO.PIVOT.TABLE(row_count=1)", async function (assert) { setCellContent(model, "A1", `=ODOO.PIVOT.TABLE("1", 1)`, "42"); // prettier-ignore assert.deepEqual(getEvaluatedGrid(model, "A1:D4", "42"), [ - ["Pivot #1", "xphone", "xpad", "Total"], - ["", "Probability", "Probability", "Probability"], - [1, "", 11, 11], - ["", "", "", ""], + ["(#1) Partner Pivot", "xphone", "xpad", "Total"], + ["", "Probability", "Probability", "Probability"], + [1, "", 11, 11], + ["", "", "", ""], ]); }); @@ -63,9 +63,9 @@ QUnit.test("ODOO.PIVOT.TABLE(row_count=0)", async function (assert) { setCellContent(model, "A1", `=ODOO.PIVOT.TABLE("1", 0)`, "42"); // prettier-ignore assert.deepEqual(getEvaluatedGrid(model, "A1:D3", "42"), [ - ["Pivot #1", "xphone", "xpad", "Total"], - ["", "Probability", "Probability", "Probability"], - ["", "", "", ""], + ["(#1) Partner Pivot", "xphone", "xpad", "Total"], + ["", "Probability", "Probability", "Probability"], + ["", "", "", ""], ]); }); @@ -123,7 +123,7 @@ QUnit.test( setCellContent(model, "A1", `=ODOO.PIVOT.TABLE("1",0,FALSE,FALSE)`, "42"); // prettier-ignore assert.deepEqual(getEvaluatedGrid(model, "A1:D1", "42"), [ - ["Pivot #1", "", "", ""], + ["(#1) Partner Pivot", "", "", ""], ]); } ); @@ -134,7 +134,7 @@ QUnit.test( setCellContent(model, "A1", `=ODOO.PIVOT.TABLE("1",0,TRUE,FALSE)`, "42"); // prettier-ignore assert.deepEqual(getEvaluatedGrid(model, "A1:D1", "42"), [ - ["Pivot #1", "", "", ""], + ["(#1) Partner Pivot", "", "", ""], ]); } ); @@ -170,32 +170,43 @@ QUnit.test("ODOO.PIVOT.TABLE with multiple row groups", async function (assert) // values from the ODOO.PIVOT.TABLE function // prettier-ignore assert.deepEqual(getEvaluatedGrid(model, "A1:D11", "42"), [ - ["Pivot #1", "xphone", "xpad", "Total"], - ["", "Probability", "Probability", "Probability"], - [1, "", 11, 11], - [2, "", 11, 11], - [2, "", 15, 15], - [4, "", 15, 15], - [12, 10, "", 10], - [1, 10, "", 10], - [17, "", 95, 95], - [3, "", 95, 95], - ["Total", 10, 121, 131], + ["(#1) Partner Pivot", "xphone", "xpad", "Total"], + ["", "Probability", "Probability", "Probability"], + [1, "", 11, 11], + [2, "", 11, 11], + [2, "", 15, 15], + [4, "", 15, 15], + [12, 10, "", 10], + [1, 10, "", 10], + [17, "", 95, 95], + [3, "", 95, 95], + ["Total", 10, 121, 131], ]); setCellContent(model, "A1", `=ODOO.PIVOT.TABLE("1",,FALSE)`, "42"); // values from the ODOO.PIVOT.TABLE function without any group totals // prettier-ignore assert.deepEqual(getEvaluatedGrid(model, "A1:D11", "42"), [ - ["Pivot #1", "xphone", "xpad", ""], - ["", "Probability", "Probability", ""], - [1, "", "", ""], // group header but without total values - [2, "", 11, ""], - [2, "", "", ""], // group header but without total values - [4, "", 15, ""], - [12, "", "", ""], // group header but without total values - [1, 10, "", ""], - [17, "", "", ""], // group header but without total values - [3, "", 95, ""], - ["", "", "", ""], + ["(#1) Partner Pivot", "xphone", "xpad", ""], + ["", "Probability", "Probability", ""], + [1, "", "", ""], // group header but without total values + [2, "", 11, ""], + [2, "", "", ""], // group header but without total values + [4, "", 15, ""], + [12, "", "", ""], // group header but without total values + [1, 10, "", ""], + [17, "", "", ""], // group header but without total values + [3, "", 95, ""], + ["", "", "", ""], ]); }); + +QUnit.test("Renaming the pivot reevaluates the ODOO.PIVOT.TABLE function", async function (assert) { + const pivotId = model.getters.getPivotIds()[0]; + setCellContent(model, "A1", `=ODOO.PIVOT.TABLE("1")`, "42"); + assert.equal(getEvaluatedCell(model, "A1", "42").value, "(#1) Partner Pivot"); + model.dispatch("RENAME_ODOO_PIVOT", { + pivotId, + name: "New Name", + }); + assert.equal(getEvaluatedCell(model, "A1", "42").value, "(#1) New Name"); +});