From f3543be4064c5942023ec5f8156e94d4004d3cd2 Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Wed, 6 Jul 2022 12:03:37 +0000 Subject: [PATCH] [FIX] web: process context.form_view_initial_mode Before this commit, the context parameter "form_view_initial_mode" was ignored by the form views, so that the form view would not be always initialized in the appropriate mode. closes odoo/odoo#95413 Signed-off-by: Aaron Bohy (aab) --- .../src/webclient/actions/action_service.js | 15 ++++--- .../webclient/actions/window_action_tests.js | 43 +++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/webclient/actions/action_service.js b/addons/web/static/src/webclient/actions/action_service.js index a66171235e1..8d6a114e510 100644 --- a/addons/web/static/src/webclient/actions/action_service.js +++ b/addons/web/static/src/webclient/actions/action_service.js @@ -439,12 +439,15 @@ function makeActionManager(env) { }, }); - if (view.type === "form" && action.target === "new") { - viewProps.mode = "edit"; - } - - if (action.flags && "mode" in action.flags && view.type === "form") { - viewProps.mode = action.flags.mode; + if (view.type === "form") { + if (action.target === "new") { + viewProps.mode = "edit"; + } else if (context.form_view_initial_mode) { + viewProps.mode = context.form_view_initial_mode; + } + if (action.flags && "mode" in action.flags) { + viewProps.mode = action.flags.mode; + } } if (target === "inline") { 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 840fbf2adbe..91a89df656f 100644 --- a/addons/web/static/tests/webclient/actions/window_action_tests.js +++ b/addons/web/static/tests/webclient/actions/window_action_tests.js @@ -2264,4 +2264,47 @@ QUnit.module("ActionManager", (hooks) => { assert.containsNone(target, ".o_view_nocontent"); assert.containsOnce(target, "table"); }); + + QUnit.test("process context.form_view_initial_mode", async function (assert) { + serverData.views = { + "partner,false,form": `
`, + "partner,false,search": ``, + }; + + const webClient = await createWebClient({ serverData }); + await doAction(webClient, { + res_id: 1, + type: "ir.actions.act_window", + target: "current", + res_model: "partner", + views: [[false, "form"]], + context: { + form_view_initial_mode: "edit", + }, + }); + + assert.containsOnce(target, ".o_form_view .o_form_editable"); + }); + + QUnit.test("process context.form_view_initial_mode (2)", async function (assert) { + serverData.views = { + "partner,false,form": `
`, + "partner,false,search": ``, + }; + + const webClient = await createWebClient({ serverData }); + await doAction(webClient, { + res_id: 1, + type: "ir.actions.act_window", + target: "new", + res_model: "partner", + views: [[false, "form"]], + context: { + form_view_initial_mode: "readonly", + }, + }); + + // mode is "edit" because target="new" + assert.containsOnce(target, ".o_form_view .o_form_editable"); + }); });