From cdb01d52ea0a7b3b02594f2bd98d1a7bdf2fa2a3 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 1 Mar 2018 11:19:23 +0100 Subject: [FIX] web: create favorite filters in dialogs This is a manual forwardport of rev. b466b3bc608. Consider the following scenario: open in edit mode a form view containing a many2many field displayed with widget many2many_tags, on the many2many field dropdown, click on 'Search More' (it opens a dialog), and in the dialog, try to save the current search in the searchview's favorite menu. Before this rev., it crashed because it tried to retrieve the action's context (to add to the saved filter), whereas there is no action in this case. Actually, the action's context should never been used in this case. What must be used is the controller's context (this mainly makes sense for Pivot and Graph views). Fixes #23293 --- .../web/static/tests/views/view_dialogs_tests.js | 60 +++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'addons/web/static/tests/views/view_dialogs_tests.js') diff --git a/addons/web/static/tests/views/view_dialogs_tests.js b/addons/web/static/tests/views/view_dialogs_tests.js index 1f958fb38bc..6ec4f50ab4b 100644 --- a/addons/web/static/tests/views/view_dialogs_tests.js +++ b/addons/web/static/tests/views/view_dialogs_tests.js @@ -1,8 +1,9 @@ odoo.define('web.view_dialogs_tests', function (require) { "use strict"; -var testUtils = require('web.test_utils'); var dialogs = require('web.view_dialogs'); +var ListController = require('web.ListController'); +var testUtils = require('web.test_utils'); var Widget = require('web.Widget'); QUnit.module('Views', { @@ -241,6 +242,63 @@ QUnit.module('Views', { parent.destroy(); }); + QUnit.test('SelectCreateDialog: save current search', function (assert) { + assert.expect(4); + + testUtils.patch(ListController, { + getContext: function () { + return { + shouldBeInFilterContext: true, + }; + }, + }); + + var parent = createParent({ + data: this.data, + archs: { + 'partner,false,list': + '' + + '' + + '', + 'partner,false,search': + '' + + '' + + '', + + }, + intercepts: { + create_filter: function (event) { + var filter = event.data.filter; + assert.deepEqual(filter.domain, [['bar', '=', true]], + "should save the correct domain"); + assert.deepEqual(filter.context, {shouldBeInFilterContext: true}, + "should save the correct context"); + }, + }, + }); + + var dialog = new dialogs.SelectCreateDialog(parent, { + context: {shouldNotBeInFilterContext: false}, + res_model: 'partner', + }).open(); + + assert.strictEqual(dialog.$('.o_data_row').length, 3, + "should contain 3 records"); + + // filter on bar + dialog.$('.o_filters_menu a:contains(Bar)').click(); + + assert.strictEqual(dialog.$('.o_data_row').length, 2, + "should contain 2 records"); + + // save filter + dialog.$('.o_save_search a').click(); // toggle 'Save current search' + dialog.$('.o_save_name input[type=text]').val('some name'); // name the filter + dialog.$('.o_save_name button').click(); // click on 'Save' + + testUtils.unpatch(ListController); + parent.destroy(); + }); }); }); -- cgit v1.2.3