From 1d3c886b95c0191ec338ead5662eb9d787feb8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phil=C3=A9mon=20van=20Helden?= Date: Thu, 8 Apr 2021 09:54:12 +0000 Subject: [PATCH] [FIX] web: no error on single active_ids state load In eg. 13.0 when refreshing sales analysis action of a product, we would get an error because we have a single active_ids which is not expected by the code. With this commit, we use .toString() on the jQuery BBQ parsed active_ids as it was done before 32b8cec5 refactoring (january 2018). The added test with the fix fails with an error: TypeError: state.active_ids.split is not a function at Class.loadState (/web/static/src/js/chrome/action_manager_act_window.js) opw-2471982 closes odoo/odoo#70285 X-original-commit: bf9a985f4b62cc6f1eef4f9fcca2a8dfbd453004 Signed-off-by: Nicolas Lempereur (nle) Signed-off-by: pvh-odoo Co-authored-by: Nicolas Lempereur --- .../js/chrome/action_manager_act_window.js | 2 +- .../tests/chrome/action_manager_tests.js | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/chrome/action_manager_act_window.js b/addons/web/static/src/js/chrome/action_manager_act_window.js index 19cda7d3241..507d8a18217 100644 --- a/addons/web/static/src/js/chrome/action_manager_act_window.js +++ b/addons/web/static/src/js/chrome/action_manager_act_window.js @@ -86,7 +86,7 @@ ActionManager.include({ // jQuery's BBQ plugin does some parsing on values that are valid integers // which means that if there's only one item, it will do parseInt() on it, // otherwise it will keep the comma seperated list as string - context.active_ids = state.active_ids.split(',').map(function (id) { + context.active_ids = state.active_ids.toString().split(',').map(function (id) { return parseInt(id, 10) || id; }); } else if (state.active_id) { diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js index af335509afa..1820685ecc8 100644 --- a/addons/web/static/tests/chrome/action_manager_tests.js +++ b/addons/web/static/tests/chrome/action_manager_tests.js @@ -1342,6 +1342,26 @@ QUnit.module('ActionManager', { actionManager.destroy(); }); + QUnit.test('state with integer active_ids should not crash', async function (assert) { + assert.expect(0); + + var actionManager = await createActionManager({ + actions: this.actions, + mockRPC: function (route, args) { + if (route === '/web/action/run') { + return Promise.resolve(); + } + return this._super.apply(this, arguments); + }, + }); + await actionManager.loadState({ + action: 2, + active_ids: 3, + }); + + actionManager.destroy(); + }); + QUnit.module('Concurrency management'); QUnit.test('drop previous actions if possible', async function (assert) {