[IMP] spreadsheet: Improve ODOO.PIVOT.TABLE hook value

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) <rar@odoo.com>
This commit is contained in:
Rémi Rahir (rar)
2023-11-04 00:38:29 +00:00
parent 7c45aca3be
commit d11845e322
3 changed files with 47 additions and 33 deletions
@@ -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"),
@@ -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."));
@@ -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");
});