Skip to content

Commit

Permalink
[FIX] pivot: skip cells on manipulated pivot array formulas
Browse files Browse the repository at this point in the history
Steps to reproduce in odoo:

- insert a pivot with more rows than columns
- write in a cell =TRANSPOSE(ODOO.PIVOT.TABLE(1))
- right-click on the grand total value

=> boom

When computing which cell of the pivot table is clicked, we assume the matrix
comes directly from the ODOO.PIVOT.TABLE(...) function to compute the offsets
from the array formula. But it's completely wrong as the cell could at a
completely different place if the matrix is manipulated by other functions
before being outputted to the grid.

closes #5161

X-original-commit: odoo/odoo@d33a9f3
Task: 4292134
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
  • Loading branch information
LucasLefevre committed Nov 5, 2024
1 parent 595963d commit 3605505
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/plugins/ui_core_views/pivot_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ export class PivotUIPlugin extends UIPlugin {
if (!pivot.isValid()) {
return EMPTY_PIVOT_CELL;
}
if (
functionName === "PIVOT" &&
!cell.content.replaceAll(" ", "").toUpperCase().startsWith("=PIVOT")
) {
return EMPTY_PIVOT_CELL;
}
if (functionName === "PIVOT") {
const includeTotal = args[2] === false ? false : undefined;
const includeColumnHeaders = args[3] === false ? false : undefined;
Expand Down
20 changes: 20 additions & 0 deletions tests/pivots/pivot_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ describe("Pivot plugin", () => {
);
});

test("getPivotCellFromPosition cannot get the pivot cell when the table is manipulated by other functions", () => {
// prettier-ignore
const grid = {
A1: "Customer", B1: "Price", C1: '=PIVOT.VALUE(1,"Price","5","Bob")',
A2: "Alice", B2: "10",
A3: "Bob", B3: "30",
A4: "=TRANSPOSE(PIVOT(1))",
};
const model = createModelFromGrid(grid);
addPivot(model, "A1:B3", {
columns: [],
rows: [{ name: "Customer" }],
measures: [{ name: "Price", aggregator: "sum" }],
});
selectCell(model, "C5");
expect(model.getters.getPivotCellFromPosition(model.getters.getActivePosition())).toEqual(
EMPTY_PIVOT_CELL
);
});

test("forbidden characters are removed from new sheet name when duplicating a pivot", () => {
const grid = {
A1: "Customer",
Expand Down

0 comments on commit 3605505

Please sign in to comment.