From 62526a3546342ff4f289da2568d3107762b2dddb Mon Sep 17 00:00:00 2001 From: Lucas Perais Date: Mon, 17 Oct 2022 07:18:19 +0000 Subject: [PATCH] [FIX] web: discarding an existing record in form view action target new. Do an action in target new that will spawn a record in its form view. The typical example is "Edit View: XXX" in the debug systray. On the dialog, click on "Discard". Before this commit, that button did not close the dialog. After this commit, that "Discard" button closes the dialog. closes odoo/odoo#103275 X-original-commit: 08751e0eef0cefe74e626ffa8ba26a5e8f18113f Signed-off-by: Aaron Bohy (aab) Signed-off-by: Lucas Perais (lpe) --- .../static/src/views/form/form_controller.js | 2 +- .../tests/views/form/form_view_tests.js | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/views/form/form_controller.js b/addons/web/static/src/views/form/form_controller.js index a497428414b..a9f999806ca 100644 --- a/addons/web/static/src/views/form/form_controller.js +++ b/addons/web/static/src/views/form/form_controller.js @@ -441,7 +441,7 @@ export class FormController extends Component { if (this.props.onDiscard) { this.props.onDiscard(this.model.root); } - if (this.model.root.isVirtual) { + if (this.model.root.isVirtual || this.env.inDialog) { this.env.config.historyBack(); } } 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 e27c0414e87..ec6c96c587b 100644 --- a/addons/web/static/tests/views/form/form_view_tests.js +++ b/addons/web/static/tests/views/form/form_view_tests.js @@ -2762,6 +2762,37 @@ QUnit.module("Views", (hooks) => { assert.containsNone(target, ".o_dialog .o_form_view", "the dialog has been closed"); }); + QUnit.test( + "form views in dialogs closes on discard on existing record", + async function (assert) { + serverData.models.partner.records[0].foo = undefined; + delete serverData.models.partner.fields.foo.default; + 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", + res_id: 1, + }, + }; + const webClient = await createWebClient({ serverData }); + await doAction(webClient, 1); + assert.containsOnce(target, ".o_dialog .o_form_view", "the dialog has been opened"); + + await click(target.querySelector(".o_dialog .o_form_button_cancel")); + assert.containsNone(target, ".o_dialog .o_form_view", "the dialog has been closed"); + } + ); + QUnit.test("form views in dialogs do not have class o_xxl_form_view", async function (assert) { const bus = new EventBus(); registry.category("services").add("ui", {