From 721f38b11d0fdf246d32a6d334ed00bea00ac752 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 3 Aug 2020 13:30:38 +0000 Subject: [PATCH] [FIX] base: can execute action from settings Before this commit, when being in a settings form view with at least two items in the breadcrumbs (the settings view preceeded by another one), clicking on a button to execute an action didn't properly work: an history back was done instead, thus returning to the previous action. For instance, go to Sales (without demo data), click on 'Set payments' in the onboarding banner, click 'Go to the configuration panel', and in the settings view click on 'Install More Packages'. The issue has been introduced by [1], but we couldn't find a scenario to reproduce it before saas-13.3. [1] a3845ae3f058772d4b548c703f5ddf94b571d903 Issue spotted in task 2277314 closes odoo/odoo#55351 X-original-commit: 6ccb108e9a621a672fde715ea78656ffeb6834e5 Signed-off-by: Julien Mougenot (jum) Signed-off-by: Aaron Bohy (aab) --- .../base/static/src/js/res_config_settings.js | 2 +- .../base/static/tests/base_settings_tests.js | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/static/src/js/res_config_settings.js b/odoo/addons/base/static/src/js/res_config_settings.js index 67e2979c308..ab09eaa7c27 100644 --- a/odoo/addons/base/static/src/js/res_config_settings.js +++ b/odoo/addons/base/static/src/js/res_config_settings.js @@ -297,7 +297,7 @@ var BaseSettingController = FormController.extend({ var recordID = ev.data.recordID; var _super = this._super; var args = arguments; - this._discardChanges(recordID).then(function () { + this._discardChanges(recordID, { noAbandon: true }).then(function () { _super.apply(self, args); }); } else { diff --git a/odoo/addons/base/static/tests/base_settings_tests.js b/odoo/addons/base/static/tests/base_settings_tests.js index fa9b92c49e2..ec08e7ee17f 100644 --- a/odoo/addons/base/static/tests/base_settings_tests.js +++ b/odoo/addons/base/static/tests/base_settings_tests.js @@ -359,5 +359,70 @@ QUnit.module('base_settings_tests', { form.destroy(); }); + QUnit.test('execute action from settings view with several actions in the breadcrumb', async function (assert) { + // This commit fixes a race condition, that's why we artificially slow down a read rpc + assert.expect(4); + + const actions = [{ + id: 1, + name: 'First action', + res_model: 'project', + type: 'ir.actions.act_window', + views: [[1, 'list']], + }, { + id: 2, + name: 'Settings view', + res_model: 'project', + type: 'ir.actions.act_window', + views: [[2, 'form']], + }, { + id: 3, + name: 'Other action', + res_model: 'project', + type: 'ir.actions.act_window', + views: [[3, 'list']], + }]; + const archs = { + 'project,1,list': '', + 'project,2,form': ` +
+
+
+
`, + 'project,3,list': '', + 'project,false,search': '', + }; + + let loadViewsDef; + const actionManager = await createActionManager({ + actions: actions, + archs: archs, + data: this.data, + async mockRPC(route, args) { + const _super = this._super.bind(this); + if (args.method === 'read') { + await Promise.resolve(loadViewsDef); // slow down reload of settings view + } + return _super(route, args); + }, + }); + + await actionManager.doAction(1); + assert.strictEqual(actionManager.$('.breadcrumb').text(), 'First action'); + + await actionManager.doAction(2); + assert.strictEqual(actionManager.$('.breadcrumb').text(), 'First actionNew'); + + loadViewsDef = testUtils.makeTestPromise(); + await testUtils.dom.click(actionManager.$('button[name="3"]')); + assert.strictEqual(actionManager.$('.breadcrumb').text(), 'First actionNew'); + + loadViewsDef.resolve(); + await testUtils.nextTick(); + assert.strictEqual(actionManager.$('.breadcrumb').text(), 'First actionNewOther action'); + + actionManager.destroy(); + }); }); });