From 775902531041aba129b84df9e7385835ee5ae341 Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Tue, 2 Aug 2022 08:40:07 +0000 Subject: [PATCH] [FIX] web: ViewButton not display error dialogs When a ViewButton is clicked and the action fails, you would expect to see an error dialog explaining the failure. For example: - go to a form view - click on a state button which should open another view - the new view has an issue when rendered Result before: We stay on the form view and nothing happens Result after: We stay on the form view and an error dialog is displayed. Part-of: odoo/odoo#97295 --- .../src/views/view_button/view_button_hook.js | 8 ++- .../tests/views/form/form_view_tests.js | 51 +++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/views/view_button/view_button_hook.js b/addons/web/static/src/views/view_button/view_button_hook.js index 330f760e008..c7292c71269 100644 --- a/addons/web/static/src/views/view_button/view_button_hook.js +++ b/addons/web/static/src/views/view_button/view_button_hook.js @@ -80,12 +80,16 @@ export function useViewButtons(model, ref, options = {}) { comp.render(true); // FIXME WOWL reactivity }, }); + let error; try { await action.doActionButton(doActionParams); } catch (_e) { + error = _e; await doActionParams.onClose(); - } finally { - enableButtons(getEl(), manuallyDisabledButtons); + } + enableButtons(getEl(), manuallyDisabledButtons); + if (error) { + return Promise.reject(error); } } 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 f79aa4e294f..666823b4a12 100644 --- a/addons/web/static/tests/views/form/form_view_tests.js +++ b/addons/web/static/tests/views/form/form_view_tests.js @@ -1,5 +1,6 @@ /** @odoo-module **/ +import { registerCleanup } from "@web/../tests/helpers/cleanup"; import { makeFakeNotificationService } from "@web/../tests/helpers/mock_services"; import { click, @@ -11351,4 +11352,54 @@ QUnit.module("Views", (hooks) => { }); assert.containsOnce(target, ".o_field_legacy_one2many .o_legacy_list_view"); }); + + QUnit.test("Action Button clicked with failing action", async function (assert) { + const handler = (ev) => { + assert.step("error"); + // need to preventDefault to remove error from console (so python test pass) + ev.preventDefault(); + }; + window.addEventListener("unhandledrejection", handler); + registerCleanup(() => window.removeEventListener("unhandledrejection", handler)); + patchWithCleanup(QUnit, { + onUnhandledRejection: () => {}, + }); + + class MyComponent extends Component { + setup() { + throw new Error("test"); + } + } + MyComponent.template = xml`
`; + registry.category("actions").add("someaction", MyComponent); + + 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", + view_mode: "form", + views: [[false, "form"]], + }); + assert.containsOnce(target, ".o_form_view .test"); + + await click(target.querySelector(".oe_stat_button")); + assert.containsOnce(target, ".o_form_view .test"); + assert.verifySteps(["error"]); + }); });