Skip to content

Commit b8b9259

Browse files
LucasLefevrerrahir
authored andcommitted
[FIX] pivot: add deferred calculated measure
Steps to reproduce: - Open a pivot side panel - click on "Defer update" - add a calculated measure => boom It's looking for the compiled formula in the plugin, but it doesn't exist since the pivot was not updated yet. It's ok to (re)compile the formula everytime in the side panel, it's only one formula and it's not a hot path. closes #7207 Task: 5096156 X-original-commit: e7fd672 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com> Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
1 parent c8a9f81 commit b8b9259

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/components/side_panel/pivot/pivot_layout_configurator/pivot_measure/pivot_measure.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component } from "@odoo/owl";
22
import { PIVOT_TOKEN_COLOR } from "../../../../../constants";
3-
import { Token } from "../../../../../formulas";
3+
import { Token, compile } from "../../../../../formulas";
44
import { unquote } from "../../../../../helpers";
55
import { PivotRuntimeDefinition } from "../../../../../helpers/pivot/pivot_runtime_definition";
66
import { createMeasureAutoComplete } from "../../../../../registries/auto_completes/pivot_dimension_auto_complete";
@@ -103,6 +103,6 @@ export class PivotMeasureEditor extends Component<Props> {
103103
}
104104

105105
get isCalculatedMeasureInvalid(): boolean {
106-
return this.env.model.getters.getMeasureCompiledFormula(this.props.measure).isBadExpression;
106+
return compile(this.props.measure.computedBy?.formula ?? "").isBadExpression;
107107
}
108108
}

tests/pivots/spreadsheet_pivot/spreadsheet_pivot_side_panel.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,20 @@ describe("Spreadsheet pivot side panel", () => {
421421
expect(fixture.querySelectorAll(".pivot-dimension")).toHaveLength(0);
422422
});
423423

424+
test("can add a calculated measure with defer update", async () => {
425+
await click(fixture.querySelector(".pivot-defer-update input")!);
426+
await click(fixture.querySelectorAll(".add-dimension")[2]);
427+
await click(fixture, ".add-calculated-measure");
428+
429+
await editStandaloneComposer(".pivot-dimension .o-composer", "=1+");
430+
await click(fixture.querySelector(".sp_apply_update")!);
431+
expect(".o-standalone-composer.o-invalid").toHaveCount(1);
432+
433+
await editStandaloneComposer(".pivot-dimension .o-composer", "=1+1");
434+
await click(fixture.querySelector(".sp_apply_update")!);
435+
expect(model.getters.getPivotCoreDefinition("1").measures[0].computedBy?.formula).toBe("=1+1");
436+
});
437+
424438
test("filter unsupported measures", async () => {
425439
setCellContent(model, "A1", "integer");
426440
setCellContent(model, "A2", "10");

0 commit comments

Comments
 (0)