From 951270d12f45328c41579954eaef0c858c64e365 Mon Sep 17 00:00:00 2001 From: "Achraf (abz)" Date: Tue, 9 Nov 2021 14:09:28 +0000 Subject: [PATCH] [FIX] web: legacy action_menus: provide context to executeAction In a list view in multicompany: - select all records with the main checkbox above the list - click on "Select All" to select every record for that domain - open the "Actions" dropdown and try to do an action Before this commit, there may be a fail on some records due to some records not belonging to the right company. This was because when fetching the active_ids from the server, the context, and hence the allowed companies, was not passed to the RPC. After this commit, the call to retrieve active_ids contains the allowed companies and the correct records are returned and treated. opw-2669292 closes odoo/odoo#79795 X-original-commit: 894430076423c81ec0804158249c354115030e9e Signed-off-by: Lucas Perais (lpe) Signed-off-by: Achraf --- .../src/legacy/js/components/action_menus.js | 1 + .../legacy/components/action_menus_tests.js | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/addons/web/static/src/legacy/js/components/action_menus.js b/addons/web/static/src/legacy/js/components/action_menus.js index ed95e6663fa..06bf3be3207 100644 --- a/addons/web/static/src/legacy/js/components/action_menus.js +++ b/addons/web/static/src/legacy/js/components/action_menus.js @@ -120,6 +120,7 @@ odoo.define('web.ActionMenus', function (require) { args: [this.props.domain], kwargs: { limit: this.env.session.active_ids_limit, + context: this.props.context, }, }); } diff --git a/addons/web/static/tests/legacy/components/action_menus_tests.js b/addons/web/static/tests/legacy/components/action_menus_tests.js index ab2aac9be9c..8cbf6ff738d 100644 --- a/addons/web/static/tests/legacy/components/action_menus_tests.js +++ b/addons/web/static/tests/legacy/components/action_menus_tests.js @@ -246,5 +246,33 @@ odoo.define('web.action_menus_tests', function (require) { actionMenus.destroy(); }); + + QUnit.test('execute action with context', async function (assert) { + assert.expect(1); + const actionMenus = await createComponent(ActionMenus, { + env: { + action: this.action, + view: this.view, + }, + props: { + ...this.props, + isDomainSelected: true, + context: { + allowed_company_ids: [112], + }, + }, + async mockRPC(route, args) { + if (route === "/web/dataset/call_kw/hobbit/search"){ + assert.deepEqual(args.kwargs.context, { allowed_company_ids: [112] }, "The kwargs should contains the right context"); + } + return this._super(...arguments); + }, + }); + + await testUtils.controlPanel.toggleActionMenu(actionMenus, "Action"); + await testUtils.controlPanel.toggleMenuItem(actionMenus, "What's taters, precious ?"); + + actionMenus.destroy(); + }); }); });