From 0a64516858af2f4b861a3eec20c6b1a5a6782aa3 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 6 Jul 2023 09:23:26 +0000 Subject: [PATCH] [FIX] web: form: do not add display_name if in dialog In form views, the "display_name" field is automatically added to the list of activeFields as we need its value to display in the breadcrumbs. However, this isn't necessary when there's no control panel, in particular in dialogs. Without this commit, the test "test_addremove" of addon test_apikeys didn't pass. Part of task~3179751 Part-of: odoo/odoo#114024 --- .../static/src/views/form/form_controller.js | 12 ++++----- .../tests/views/form/form_view_tests.js | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/views/form/form_controller.js b/addons/web/static/src/views/form/form_controller.js index 101f0242bf2..a5b9be38909 100644 --- a/addons/web/static/src/views/form/form_controller.js +++ b/addons/web/static/src/views/form/form_controller.js @@ -136,6 +136,11 @@ export class FormController extends Component { ); this.model = useState(new this.props.Model(this.env, this.modelParams, modelServices)); + this.display = { ...this.props.display }; + if (this.env.inDialog) { + this.display.controlPanel = false; + } + onWillStart(async () => { await loadSubViews( this.archInfo.fieldNodes, @@ -150,7 +155,7 @@ export class FormController extends Component { this.archInfo, this.props.fields ); - if (this.props.display.controlPanel) { + if (this.display.controlPanel) { addFieldDependencies(activeFields, fields, [ { name: "display_name", type: "char", readonly: true }, ]); @@ -167,11 +172,6 @@ export class FormController extends Component { this.cpButtonsRef = useRef("cpButtons"); - this.display = { ...this.props.display }; - if (this.env.inDialog) { - this.display.controlPanel = false; - } - useEffect(() => { if (!this.env.inDialog) { this.updateURL(); diff --git a/addons/web/static/tests/views/form/form_view_tests.js b/addons/web/static/tests/views/form/form_view_tests.js index ae3577f9dfb..b92a4b6e145 100644 --- a/addons/web/static/tests/views/form/form_view_tests.js +++ b/addons/web/static/tests/views/form/form_view_tests.js @@ -2951,6 +2951,33 @@ QUnit.module("Views", (hooks) => { assert.containsNone(target, ".o_dialog .o_form_view .o_control_panel"); }); + QUnit.test("form views in dialogs do not add display_name field", async function (assert) { + assert.expect(3); + + serverData.views = { + "partner,false,form": `
`, + }; + serverData.actions = { + 1: { + id: 1, + name: "Partner", + res_model: "partner", + type: "ir.actions.act_window", + views: [[false, "form"]], + target: "new", + }, + }; + const mockRPC = function (route, args) { + if (args.method === "onchange2") { + assert.deepEqual(args.args[3], { foo: {} }); + } + } + const webClient = await createWebClient({ serverData, mockRPC }); + await doAction(webClient, 1); + assert.containsOnce(target, ".o_dialog .o_form_view"); + assert.containsNone(target, ".o_dialog .o_form_view .o_control_panel"); + }); + QUnit.test("form views in dialogs closes on save", async function (assert) { serverData.models.partner.records[0].foo = undefined; delete serverData.models.partner.fields.foo.default;