Skip to content

Commit

Permalink
[FIX] spreadsheet: correctly get pivot id from position
Browse files Browse the repository at this point in the history
Steps to reproduce in 17.0:

There's no way to reproduce the issue in 17.0 because the faulty getter in
only called on positions in the active sheet (pivot autofill, global filter
auto-matching)

Steps to reproduce in saas-17.1:

- insert a pivot in a blank spreadsheet
- delete all pivot formulas
- insert a new sheet
- in the new sheet:
	- in A1: type "1"
	- in A2: =ODOO.PIVOT(A1)
- activate the first sheet again
- Open the Data menu
=> the pivot 1 is marked as being unused, even though it's used in the second
   sheet

closes #4516

Task: 3859472
X-original-commit: 9753532
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
  • Loading branch information
pro-odoo authored and LucasLefevre committed Jun 25, 2024
1 parent ccd30df commit f79b689
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/plugins/ui_core_views/pivot_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ export class PivotUIPlugin extends UIPlugin {
getPivotIdFromPosition(position: CellPosition) {
const cell = this.getters.getCorrespondingFormulaCell(position);
if (cell && cell.isFormula) {
const pivotFunction = this.getFirstPivotFunction(cell.compiledFormula.tokens);
const pivotFunction = this.getFirstPivotFunction(
position.sheetId,
cell.compiledFormula.tokens
);
if (pivotFunction) {
const pivotId = pivotFunction.args[0]?.toString();
return pivotId && this.getters.getPivotId(pivotId);
Expand All @@ -124,13 +127,16 @@ export class PivotUIPlugin extends UIPlugin {
isSpillPivotFormula(position: CellPosition) {
const cell = this.getters.getCorrespondingFormulaCell(position);
if (cell && cell.isFormula) {
const pivotFunction = this.getFirstPivotFunction(cell.compiledFormula.tokens);
const pivotFunction = this.getFirstPivotFunction(
position.sheetId,
cell.compiledFormula.tokens
);
return pivotFunction?.functionName === "PIVOT";
}
return false;
}

getFirstPivotFunction(tokens: Token[]) {
getFirstPivotFunction(sheetId: UID, tokens: Token[]) {
const pivotFunction = getFirstPivotFunction(tokens);
if (!pivotFunction) {
return undefined;
Expand All @@ -147,7 +153,7 @@ export class PivotUIPlugin extends UIPlugin {
return argAst.value;
}
const argsString = astToFormula(argAst);
return this.getters.evaluateFormula(this.getters.getActiveSheetId(), argsString);
return this.getters.evaluateFormula(sheetId, argsString);
});
return { functionName, args: evaluatedArgs };
}
Expand All @@ -171,7 +177,10 @@ export class PivotUIPlugin extends UIPlugin {
return EMPTY_PIVOT_CELL;
}
const mainPosition = this.getters.getCellPosition(cell.id);
const result = this.getters.getFirstPivotFunction(cell.compiledFormula.tokens);
const result = this.getters.getFirstPivotFunction(
position.sheetId,
cell.compiledFormula.tokens
);
if (!result) {
return EMPTY_PIVOT_CELL;
}
Expand Down

0 comments on commit f79b689

Please sign in to comment.