summaryrefslogtreecommitdiff
path: root/addons/web/static
diff options
context:
space:
mode:
authorLucas Lefèvre <lul@odoo.com>2020-04-01 07:08:41 +0000
committerAaron Bohy <aab@odoo.com>2020-04-02 21:06:25 +0000
commit124829263021c64f6a003805d9311774372ed23b (patch)
treef6fd8a1a04131c42e6bde9bc96449f0fa383b6da /addons/web/static
parenta768937a398cb6075dc9b4a36b8f732270b8e0ed (diff)
[FIX] web,*: Remove undefined domain in action menu context
*google_drive Go to a user form view and click on "Change Password" in the action menus. => traceback `Cannot read property 'constructor' of undefined` This error is raised because `active_domain: undefined` is in the context and py_eval can't handle an undefined value. closes odoo/odoo#48915 X-original-commit: 69694c627be42e3d068e48be14026493628a3a8d Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Signed-off-by: lul-odoo <LucasLefevre@users.noreply.github.com> Co-authored-by: aab-odoo <aab@odoo.com>
Diffstat (limited to 'addons/web/static')
-rw-r--r--addons/web/static/src/js/components/action_menus.js6
-rw-r--r--addons/web/static/tests/chrome/action_manager_tests.js43
-rw-r--r--addons/web/static/tests/helpers/mock_server.js2
-rw-r--r--addons/web/static/tests/helpers/test_utils_mock.js6
4 files changed, 50 insertions, 7 deletions
diff --git a/addons/web/static/src/js/components/action_menus.js b/addons/web/static/src/js/components/action_menus.js
index 22e549a271e..4427ac5c948 100644
--- a/addons/web/static/src/js/components/action_menus.js
+++ b/addons/web/static/src/js/components/action_menus.js
@@ -109,10 +109,12 @@ odoo.define('web.ActionMenus', function (require) {
active_id: activeIds[0],
active_ids: activeIds,
active_model: this.env.action.res_model,
+ };
+ if (this.props.domain) {
// keep active_domain in context for backward compatibility
// reasons, and to allow actions to bypass the active_ids_limit
- active_domain: this.props.domain,
- };
+ activeIdsContext.active_domain = this.props.domain;
+ }
const context = new Context(this.props.context, activeIdsContext).eval();
const result = await this.rpc({
diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js
index 3fd3598000a..5af731abf81 100644
--- a/addons/web/static/tests/chrome/action_manager_tests.js
+++ b/addons/web/static/tests/chrome/action_manager_tests.js
@@ -3702,6 +3702,49 @@ QUnit.module('ActionManager', {
actionManager.destroy();
});
+ QUnit.test('execute a contextual action from a form view', async function (assert) {
+ assert.expect(4);
+
+ const contextualAction = this.actions.find(action => action.id === 8);
+ contextualAction.context = "{}"; // need a context to evaluate
+
+ const actionManager = await createActionManager({
+ actions: this.actions,
+ archs: this.archs,
+ data: this.data,
+ mockRPC: async function (route, args) {
+ const res = await this._super(...arguments);
+ if (args.method === 'load_views' && args.model === 'partner') {
+ assert.strictEqual(args.kwargs.options.toolbar, true,
+ "should ask for toolbar information");
+ res.form.toolbar = {
+ action: [contextualAction],
+ print: [],
+ };
+ }
+ return res;
+ },
+ intercepts: {
+ do_action: function (ev) {
+ actionManager.doAction(ev.data.action, {});
+ },
+ },
+ });
+
+ // execute an action and open a record
+ await actionManager.doAction(3);
+ assert.containsOnce(actionManager, '.o_list_view');
+ await testUtils.dom.click(actionManager.$('.o_data_row:first'));
+ assert.containsOnce(actionManager, '.o_form_view');
+
+ // execute the custom action from the action menu
+ await cpHelpers.toggleActionMenu(actionManager);
+ await cpHelpers.toggleMenuItem(actionManager, "Favorite Ponies");
+ assert.containsOnce(actionManager, '.o_list_view');
+
+ actionManager.destroy();
+ });
+
QUnit.module('Actions in target="new"');
QUnit.test('can execute act_window actions in target="new"', async function (assert) {
diff --git a/addons/web/static/tests/helpers/mock_server.js b/addons/web/static/tests/helpers/mock_server.js
index d59cafacd28..6879c967b2f 100644
--- a/addons/web/static/tests/helpers/mock_server.js
+++ b/addons/web/static/tests/helpers/mock_server.js
@@ -1297,7 +1297,7 @@ var MockServer = Class.extend({
_performRpc: function (route, args) {
switch (route) {
case '/web/action/load':
- return Promise.resolve(this._mockLoadAction(args.kwargs));
+ return Promise.resolve(this._mockLoadAction(args));
case '/web/dataset/search_read':
return Promise.resolve(this._mockSearchReadController(args));
diff --git a/addons/web/static/tests/helpers/test_utils_mock.js b/addons/web/static/tests/helpers/test_utils_mock.js
index 9e87c4e76da..414a9c0df64 100644
--- a/addons/web/static/tests/helpers/test_utils_mock.js
+++ b/addons/web/static/tests/helpers/test_utils_mock.js
@@ -264,10 +264,8 @@ async function addMockEnvironment(widget, params) {
intercept(widget, 'load_action', function (event) {
mockServer.performRpc('/web/action/load', {
- kwargs: {
- action_id: event.data.actionID,
- additional_context: event.data.context,
- },
+ action_id: event.data.actionID,
+ additional_context: event.data.context,
}).then(function (action) {
event.data.on_success(action);
});