From 29f83c0306080d8c3bdda5b71fef5b7ddbbc4a3c Mon Sep 17 00:00:00 2001 From: luvi Date: Tue, 26 Oct 2021 06:48:49 +0000 Subject: [PATCH] [FIX] web: missing template when editing ControlPanel This fix adresses an issue when editing the control panel from Owl based views. Currently, if you don't have a custom search to an Owl view, the template editor will appear blank as the component misses its searchViewId value from its props. The commit also introduce a test when clicking the edit ControlPanel button in that case. With the fix, you can edit the search template and get the default template closes odoo/odoo#79023 X-original-commit: f5c8e855f07d68a34dccd9977b53999911a66f62 Signed-off-by: Aaron Bohy (aab) --- addons/web/static/src/views/view.js | 3 +- .../tests/core/debug/debug_manager_tests.js | 61 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/views/view.js b/addons/web/static/src/views/view.js index 3af0cbfb574..6cf455024a4 100644 --- a/addons/web/static/src/views/view.js +++ b/addons/web/static/src/views/view.js @@ -162,6 +162,7 @@ export class View extends Component { view[0] = viewDescription.viewId; searchViewDescription = viewDescriptions.search; if (loadSearchView) { + searchViewId = searchViewId || searchViewDescription.viewId; if (!searchViewArch) { searchViewArch = searchViewDescription.arch; searchViewFields = searchViewDescription.fields; @@ -235,7 +236,7 @@ export class View extends Component { } } - // prepare the WithSearh component props + // prepare the WithSearch component props this.withSearchProps = { ...this.props, Component: ViewClass, diff --git a/addons/web/static/tests/core/debug/debug_manager_tests.js b/addons/web/static/tests/core/debug/debug_manager_tests.js index 48fd9eb55c1..ddd9c73e8e7 100644 --- a/addons/web/static/tests/core/debug/debug_manager_tests.js +++ b/addons/web/static/tests/core/debug/debug_manager_tests.js @@ -7,6 +7,7 @@ import { registry } from "@web/core/registry"; import { useDebugCategory, useOwnDebugContext } from "@web/core/debug/debug_context"; import { ormService } from "@web/core/orm_service"; import { uiService } from "@web/core/ui/ui_service"; +import { useSetupView } from "@web/views/helpers/view_hook"; import { ActionDialog } from "@web/webclient/actions/action_dialog"; import { hotkeyService } from "@web/core/hotkeys/hotkey_service"; import { registerCleanup } from "../../helpers/cleanup"; @@ -417,6 +418,66 @@ QUnit.module("DebugMenu", (hooks) => { ); }); + QUnit.test("edit search view on action without search_view_id", async (assert) => { + // When the kanban view will be converted to Owl, this test could be simplified by + // removing the toy view and using the kanban view directly + prepareRegistriesWithCleanup(); + + class ToyView extends Component { + setup() { + useSetupView(); + } + } + ToyView.template = xml`
`; + ToyView.type = "toy"; + ToyView.display_name = "toy view"; + registry.category("views").add("toy", ToyView); + + const mockRPC = async (route, args) => { + if (args.method === "check_access_rights") { + return Promise.resolve(true); + } + }; + + patchWithCleanup(odoo, { + debug: true, + }); + + registry.category("debug").category("view").add("editSearchViewItem", editSearchView); + + const serverData = getActionManagerServerData(); + serverData.actions[1] = { + id: 1, + xml_id: "action_1", + name: "Partners Action 1", + res_model: "partner", + type: "ir.actions.act_window", + views: [[false, "toy"]], + search_view_id: false, + }; + serverData.models["ir.ui.view"] = { + fields: {}, + records: [{ id: 293 }], + }; + serverData.views = {}; + serverData.views["ir.ui.view,false,form"] = `
`; + serverData.views["partner,false,toy"] = ``; + serverData.views["partner,293,search"] = ``; + + const webClient = await createWebClient({ serverData, mockRPC }); + await doAction(webClient, 1); + assert.containsOnce(webClient, ".o-toy-view"); + + await click(webClient.el.querySelector(".o_debug_manager button")); + await click(webClient.el.querySelector(".o_debug_manager .dropdown-item")); + await legacyExtraNextTick(); + assert.containsOnce(webClient, ".modal .o_form_view"); + assert.strictEqual( + webClient.el.querySelector(".modal .o_form_view .o_field_widget[name=id]").value, + "293" + ); + }); + QUnit.test( "cannot edit the control panel of a form view contained in a dialog without control panel.", async (assert) => {