[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) <aab@odoo.com>
This commit is contained in:
@@ -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") {
|
||||
|
||||
@@ -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": `<form><field name="name"/></form>`,
|
||||
"partner,false,search": `<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": `<form><field name="name"/></form>`,
|
||||
"partner,false,search": `<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");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user