Skip to content

Commit f7721af

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 #7019 Task: 5043187 X-original-commit: 97ccf4c Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
1 parent be9b20b commit f7721af

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
@@ -25,6 +25,7 @@ import {
2525
UID,
2626
UpdatePivotCommand,
2727
invalidateEvaluationCommands,
28+
isMatrix,
2829
} from "../../types";
2930
import { Pivot } from "../../types/pivot_runtime";
3031
import { CoreViewPlugin, CoreViewPluginConfig } from "../core_view_plugin";
@@ -202,7 +203,7 @@ export class PivotUIPlugin extends CoreViewPlugin {
202203
if (!result) {
203204
return EMPTY_PIVOT_CELL;
204205
}
205-
const { functionName, args } = result;
206+
let { functionName, args } = result;
206207
const formulaId = args[0];
207208
if (!formulaId) {
208209
return EMPTY_PIVOT_CELL;
@@ -241,6 +242,9 @@ export class PivotUIPlugin extends CoreViewPlugin {
241242
return pivotCells[pivotCol][pivotRow];
242243
}
243244
try {
245+
const offsetRow = position.row - mainPosition.row;
246+
const offsetCol = position.col - mainPosition.col;
247+
args = args.map((arg) => (isMatrix(arg) ? arg[offsetCol][offsetRow] : arg));
244248
if (functionName === "PIVOT.HEADER" && args.at(-2) === "measure") {
245249
const domain = pivot.parseArgsToPivotDomain(
246250
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
@@ -205,6 +205,33 @@ describe("Pivot plugin", () => {
205205
);
206206
});
207207

208+
test("getPivotCellFromPosition can handle vectorization", () => {
209+
// prettier-ignore
210+
const grid = {
211+
A1: "Stage", B1: "Price", C1: '=PIVOT.VALUE(1,"Price","Stage",SEQUENCE(2))',
212+
A2: "1", B2: "10",
213+
A3: "2", B3: "30",
214+
};
215+
const model = createModelFromGrid(grid);
216+
addPivot(model, "A1:B3", {
217+
columns: [],
218+
rows: [{ fieldName: "Stage" }],
219+
measures: [{ id: "price:sum", fieldName: "Price", aggregator: "sum" }],
220+
});
221+
selectCell(model, "C1");
222+
expect(model.getters.getPivotCellFromPosition(model.getters.getActivePosition())).toMatchObject(
223+
{
224+
domain: [{ field: "Stage", type: "integer", value: 1 }],
225+
}
226+
);
227+
selectCell(model, "C2");
228+
expect(model.getters.getPivotCellFromPosition(model.getters.getActivePosition())).toMatchObject(
229+
{
230+
domain: [{ field: "Stage", type: "integer", value: 2 }],
231+
}
232+
);
233+
});
234+
208235
test("cannot update a pivot with a wrong id", () => {
209236
const model = new Model();
210237
const updateResult = model.dispatch("UPDATE_PIVOT", {

0 commit comments

Comments
 (0)