Skip to content

Commit 97ccf4c

Browse files
committed
[FIX] pivot: handle vectorized formula
Steps to reproduce: - Create a pivot.value formula with a SEQUENCE => `getPivotCellFromPosition` returns an incorrect domain. closes #6999 Task: 5043187 Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
1 parent ea7ea0a commit 97ccf4c

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/plugins/ui_core_views/pivot_ui.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
UID,
2323
UpdatePivotCommand,
2424
invalidateEvaluationCommands,
25+
isMatrix,
2526
} from "../../types";
2627
import { Pivot } from "../../types/pivot_runtime";
2728
import { UIPlugin, UIPluginConfig } from "../ui_plugin";
@@ -198,7 +199,7 @@ export class PivotUIPlugin extends UIPlugin {
198199
if (!result) {
199200
return EMPTY_PIVOT_CELL;
200201
}
201-
const { functionName, args } = result;
202+
let { functionName, args } = result;
202203
const formulaId = args[0];
203204
if (!formulaId) {
204205
return EMPTY_PIVOT_CELL;
@@ -231,6 +232,9 @@ export class PivotUIPlugin extends UIPlugin {
231232
return pivotCells[pivotCol][pivotRow];
232233
}
233234
try {
235+
const offsetRow = position.row - mainPosition.row;
236+
const offsetCol = position.col - mainPosition.col;
237+
args = args.map((arg) => (isMatrix(arg) ? arg[offsetCol][offsetRow] : arg));
234238
if (functionName === "PIVOT.HEADER" && args.at(-2) === "measure") {
235239
const domain = pivot.parseArgsToPivotDomain(
236240
args.slice(1, -2).map((value) => ({ value } as FunctionResultObject))

tests/pivots/pivot_plugin.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,33 @@ describe("Pivot plugin", () => {
186186
);
187187
});
188188

189+
test("getPivotCellFromPosition can handle vectorization", () => {
190+
// prettier-ignore
191+
const grid = {
192+
A1: "Stage", B1: "Price", C1: '=PIVOT.VALUE(1,"Price","Stage",SEQUENCE(2))',
193+
A2: "1", B2: "10",
194+
A3: "2", B3: "30",
195+
};
196+
const model = createModelFromGrid(grid);
197+
addPivot(model, "A1:B3", {
198+
columns: [],
199+
rows: [{ fieldName: "Stage" }],
200+
measures: [{ id: "price:sum", fieldName: "Price", aggregator: "sum" }],
201+
});
202+
selectCell(model, "C1");
203+
expect(model.getters.getPivotCellFromPosition(model.getters.getActivePosition())).toMatchObject(
204+
{
205+
domain: [{ field: "Stage", type: "integer", value: 1 }],
206+
}
207+
);
208+
selectCell(model, "C2");
209+
expect(model.getters.getPivotCellFromPosition(model.getters.getActivePosition())).toMatchObject(
210+
{
211+
domain: [{ field: "Stage", type: "integer", value: 2 }],
212+
}
213+
);
214+
});
215+
189216
test("cannot update a pivot with a wrong id", () => {
190217
const model = new Model();
191218
const updateResult = model.dispatch("UPDATE_PIVOT", {

0 commit comments

Comments
 (0)