diff --git a/addons/spreadsheet/static/src/pivot/pivot_actions.js b/addons/spreadsheet/static/src/pivot/pivot_actions.js index 87fd98af8171e..0bdf0ece82b4d 100644 --- a/addons/spreadsheet/static/src/pivot/pivot_actions.js +++ b/addons/spreadsheet/static/src/pivot/pivot_actions.js @@ -27,7 +27,13 @@ export const SEE_RECORDS_PIVOT_VISIBLE = (position, env) => { const cell = env.model.getters.getCorrespondingFormulaCell(position); const evaluatedCell = env.model.getters.getEvaluatedCell(position); const argsDomain = env.model.getters.getPivotDomainArgsFromPosition(position); + const pivotId = env.model.getters.getPivotIdFromPosition(position); + if (!env.model.getters.isExistingPivot(pivotId)) { + return false; + } + const dataSource = env.model.getters.getPivotDataSource(pivotId); return ( + dataSource.isReady() && evaluatedCell.type !== "empty" && evaluatedCell.type !== "error" && argsDomain !== undefined && diff --git a/addons/spreadsheet/static/src/pivot/plugins/pivot_ui_plugin.js b/addons/spreadsheet/static/src/pivot/plugins/pivot_ui_plugin.js index fb4a13206029b..f9a87ca50281b 100644 --- a/addons/spreadsheet/static/src/pivot/plugins/pivot_ui_plugin.js +++ b/addons/spreadsheet/static/src/pivot/plugins/pivot_ui_plugin.js @@ -188,7 +188,7 @@ export class PivotUIPlugin extends spreadsheet.UIPlugin { const cell = this.getters.getCorrespondingFormulaCell(position); if (cell && cell.isFormula) { const pivotFunction = this.getters.getFirstPivotFunction(cell.compiledFormula.tokens); - if (pivotFunction) { + if (pivotFunction && pivotFunction.args[0]) { return pivotFunction.args[0]?.toString(); } } diff --git a/addons/spreadsheet/static/tests/pivots/pivot_see_records_test.js b/addons/spreadsheet/static/tests/pivots/pivot_see_records_test.js index 6dfa1fd8fb826..eb91b9929f42d 100644 --- a/addons/spreadsheet/static/tests/pivots/pivot_see_records_test.js +++ b/addons/spreadsheet/static/tests/pivots/pivot_see_records_test.js @@ -1,5 +1,5 @@ /** @odoo-module */ -import { nextTick } from "@web/../tests/helpers/utils"; +import { makeDeferred, nextTick } from "@web/../tests/helpers/utils"; import { selectCell } from "@spreadsheet/../tests/utils/commands"; import { doMenuAction, getActionMenu } from "@spreadsheet/../tests/utils/ui"; @@ -183,3 +183,30 @@ QUnit.test("Can see records on ODOO.PIVOT.TABLE cells", async function (assert) setCellContent(model, "A3", `=ODOO.PIVOT.TABLE("1",,,FALSE)`, "42"); await checkCells(data_cells); }); + +QUnit.test( + "See records is not visible if the pivot is not loaded, even if the cell has a value", + async function (assert) { + let deferred = undefined; + const { env, model } = await createSpreadsheetWithPivot({ + arch: /*xml*/ ` + + + + `, + mockRPC: async function (route, args) { + if (deferred && args.method === "read_group" && args.model === "partner") { + await deferred; + } + }, + }); + setCellContent(model, "A1", '=IFERROR(ODOO.PIVOT("1","probability"), 42)'); + deferred = makeDeferred(); + model.dispatch("REFRESH_ALL_DATA_SOURCES"); + const action = cellMenuRegistry.getAll().find((item) => item.id === "pivot_see_records"); + assert.strictEqual(action.isVisible(env), false); + deferred.resolve(); + await nextTick(); + assert.strictEqual(action.isVisible(env), true); + } +);