From a49e569bef601d077037144f2e9a47968a26fefa Mon Sep 17 00:00:00 2001 From: Philippe Wauthy Date: Tue, 21 Dec 2021 15:25:06 +0000 Subject: [PATCH] [FIX] web: remove search_default and group_by context keys when clicking on graph closes odoo/odoo#80463 Signed-off-by: Kevin Baptiste --- .../web/static/src/views/graph/graph_view.js | 6 +++ .../static/tests/views/graph_view_tests.js | 50 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/addons/web/static/src/views/graph/graph_view.js b/addons/web/static/src/views/graph/graph_view.js index e7008d015b9..04819fb673b 100644 --- a/addons/web/static/src/views/graph/graph_view.js +++ b/addons/web/static/src/views/graph/graph_view.js @@ -71,6 +71,12 @@ export class GraphView extends Component { onGraphClicked(domain) { const { context, resModel, title } = this.model.metaData; + Object.keys(context).forEach((x) => { + if (x === "group_by" || x.startsWith("search_default_")) { + delete context[x]; + } + }); + const views = {}; for (const [viewId, viewType] of this.env.config.views || []) { views[viewType] = viewId; diff --git a/addons/web/static/tests/views/graph_view_tests.js b/addons/web/static/tests/views/graph_view_tests.js index 03719369423..715e1e14148 100644 --- a/addons/web/static/tests/views/graph_view_tests.js +++ b/addons/web/static/tests/views/graph_view_tests.js @@ -2805,6 +2805,56 @@ QUnit.module("Views", (hooks) => { await clickOnDataset(graph); }); + QUnit.test("Clicking on bar charts removes group_by and search_default_* context keys", async function(assert) { + assert.expect(2); + + serviceRegistry.add( + "action", + { + start() { + return { + doAction(actionRequest, options) { + assert.deepEqual(actionRequest, { + context: { + lang: "en", + tz: "taht", + uid: 7, + }, + domain: [["bar", "=", true]], + name: "Foo Analysis", + res_model: "foo", + target: "current", + type: "ir.actions.act_window", + views: [ + [false, "list"], + [false, "form"], + ], + }); + assert.deepEqual(options, { viewType: "list" }); + }, + }; + }, + }, + { force: true } + ); + const graph = await makeView({ + serverData, + type: "graph", + resModel: "foo", + arch: ` + + + + `, + context: { + search_default_user: 1, + group_by: 'bar', + }, + }); + + await clickOnDataset(graph); + }); + QUnit.test( "clicking on a pie chart trigger a do_action with correct views", async function (assert) {