From 74586b8f4e5283db20d67461f6b9f517932e5a99 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 3 Aug 2022 08:47:12 +0000 Subject: [PATCH] [FIX] web: actionService: do not crash on unknown view type In community, some actions contain view types that only exist in enterprise (e.g. in MRP, Work Orders, there's a gantt view). Before this commit, it crashed because the view doesn't exist. This commit simply ignores those unknown views. closes odoo/odoo#97369 Signed-off-by: Samuel Degueldre --- .../src/webclient/actions/action_service.js | 6 +++-- .../webclient/actions/window_action_tests.js | 22 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/webclient/actions/action_service.js b/addons/web/static/src/webclient/actions/action_service.js index bb1c3d04d21..1148fe4d100 100644 --- a/addons/web/static/src/webclient/actions/action_service.js +++ b/addons/web/static/src/webclient/actions/action_service.js @@ -851,8 +851,10 @@ function makeActionManager(env) { const arch = viewDescriptions[type].arch; const archDoc = domParser.parseFromString(arch, "text/xml").documentElement; const jsClass = archDoc.getAttribute("js_class"); - const key = viewRegistry.contains(jsClass) ? jsClass : type; - views.push(viewRegistry.get(key)); + const view = viewRegistry.get(jsClass, false) || viewRegistry.get(type, false); + if (view) { + views.push(view); + } } } // END LEGACY CODE COMPATIBILITY diff --git a/addons/web/static/tests/webclient/actions/window_action_tests.js b/addons/web/static/tests/webclient/actions/window_action_tests.js index 3b5ec947285..70496174b94 100644 --- a/addons/web/static/tests/webclient/actions/window_action_tests.js +++ b/addons/web/static/tests/webclient/actions/window_action_tests.js @@ -938,7 +938,7 @@ QUnit.module("ActionManager", (hooks) => { "requests for execute_action of type object: disable buttons", async function (assert) { assert.expect(2); - let def; + let def = undefined; const mockRPC = async (route, args) => { if (route === "/web/dataset/call_button") { return Promise.resolve(false); @@ -1400,6 +1400,26 @@ QUnit.module("ActionManager", (hooks) => { ]); }); + QUnit.test("execute action with unknown view type", async function (assert) { + serverData.views["partner,false,unknown"] = ""; + serverData.actions[33] = { + id: 33, + name: "Partners", + res_model: "partner", + type: "ir.actions.act_window", + views: [ + [false, "list"], + [false, "unknown"], // typically, an enterprise-only view on a community db + [false, "kanban"], + [false, "form"], + ], + }; + const webClient = await createWebClient({ serverData }); + await doAction(webClient, 33); + assert.containsOnce(target, ".o_list_view"); + assert.containsN(target, ".o_cp_switch_buttons button", 2); + }); + QUnit.test("flags field of ir.actions.act_window is used", async function (assert) { // more info about flags field : https://github.com/odoo/odoo/commit/c9b133813b250e89f1f61816b0eabfb9bee2009d assert.expect(6);