From a58699cb87cce26ccca82a6e1664426ac93d792e Mon Sep 17 00:00:00 2001 From: Mohammed Shekha Date: Mon, 12 Oct 2020 12:24:06 +0000 Subject: [PATCH] [IMP] web: close confirm dialog if unlink raises error before this commit: deleting records from listview shows confirm dialog, if unlink method throws UserError then there will be two dialog, closing UserError dialog and clicking on OK button in confirm dialog will again call unlink method which will open UserError dialog again, when error thwon from unlink error then confirm dialog should close. after this commit: if error is thrown from unlink and confirm dialog is opened then cofirm dialog will close first and then error dialog will be shown, this is done to avoid situation explained above. task-2221075 closes odoo/odoo#60265 Signed-off-by: Aaron Bohy (aab) --- .../src/js/views/basic/basic_controller.js | 6 +++- addons/web/static/tests/views/list_tests.js | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js index b58a4154e1f..2f61fcb4bf6 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -344,7 +344,11 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { const message = ids.length > 1 ? _t("Are you sure you want to delete these records?") : _t("Are you sure you want to delete this record?"); - Dialog.confirm(this, message, { confirm_callback: doIt }); + let dialog; + const confirmCallback = () => { + doIt().guardedCatch(() => dialog.destroy()); + }; + dialog = Dialog.confirm(this, message, { confirm_callback: confirmCallback }); } else { doIt(); } diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 6312e4b8692..d82d03bab3b 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -3350,6 +3350,37 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('deleting record which throws UserError should close confirmation dialog', async function (assert) { + assert.expect(3); + + const list = await createView({ + View: ListView, + model: 'foo', + data: this.data, + viewOptions: {hasActionMenus: true}, + arch: '', + mockRPC: function (route, args) { + if (args.method === 'unlink') { + return Promise.reject({ message: "Odoo Server Error" }); + } + return this._super(...arguments); + }, + }); + + await testUtils.dom.click(list.$('tbody td.o_list_record_selector:first input')); + + assert.containsOnce(list.el, 'div.o_control_panel .o_cp_action_menus'); + + await cpHelpers.toggleActionMenu(list); + await cpHelpers.toggleMenuItem(list, "Delete"); + assert.containsOnce(document.body, '.modal', 'should have open the confirmation dialog'); + + await testUtils.dom.click($('body .modal button span:contains(Ok)')); + assert.containsNone(document.body, ".modal", "confirmation dialog should be closed"); + + list.destroy(); + }); + QUnit.test('delete all records matching the domain', async function (assert) { assert.expect(6);