Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions addons/spreadsheet/static/src/pivot/pivot_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
29 changes: 28 additions & 1 deletion addons/spreadsheet/static/tests/pivots/pivot_see_records_test.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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*/ `
<pivot>
<field name="probability" type="measure"/>
</pivot>
`,
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);
}
);