diff options
| author | Martin Geubelle <mge@odoo.com> | 2018-12-13 19:32:55 +0000 |
|---|---|---|
| committer | Martin Geubelle <mge@odoo.com> | 2018-12-17 10:39:03 +0000 |
| commit | ae2dbc60c5c4e23a840f79071d81f2d4c0b3fa21 (patch) | |
| tree | b47c50c058074bbf2cab716437e9922e4626daea /addons/web | |
| parent | 0794a3c95623402fb7579ca7e7465e62fa7e9669 (diff) | |
[FIX] web: handle `context` in ControlPanel <filter>
The `context` key wasn't correctly taken into account when computing the search
query for `filter``tags.
It is now correctly handled.
Task 1917628
closes odoo/odoo#29529
Diffstat (limited to 'addons/web')
4 files changed, 43 insertions, 4 deletions
diff --git a/addons/web/static/src/js/views/control_panel/control_panel_model.js b/addons/web/static/src/js/views/control_panel/control_panel_model.js index 9353022eacf..67b1a4c64f8 100644 --- a/addons/web/static/src/js/views/control_panel/control_panel_model.js +++ b/addons/web/static/src/js/views/control_panel/control_panel_model.js @@ -645,10 +645,7 @@ var ControlPanelModel = mvc.Model.extend({ * @returns {Object} context */ _getFilterContext: function (filter) { - var context = {}; - if (filter.type === 'favorite') { - _.extend(context, filter.context); - } + var context = filter.context || {}; // the following code aims to restore this: // https://github.com/odoo/odoo/blob/master/addons/web/static/src/js/views/search/search_inputs.js#L498 // this is required for the helpdesk tour to pass diff --git a/addons/web/static/src/js/views/control_panel/control_panel_view.js b/addons/web/static/src/js/views/control_panel/control_panel_view.js index 3f89ad9f637..edda0e3c9ac 100644 --- a/addons/web/static/src/js/views/control_panel/control_panel_view.js +++ b/addons/web/static/src/js/views/control_panel/control_panel_view.js @@ -143,6 +143,7 @@ var ControlPanelView = Factory.extend({ 'Ω'; if (filter.type === 'filter') { filter.domain = attrs.domain; + filter.context = pyUtils.eval('context', attrs.context); if (attrs.date) { filter.fieldName = attrs.date; filter.fieldType = this.fields[attrs.date].type; @@ -198,6 +199,7 @@ var ControlPanelView = Factory.extend({ var groupOfGroupBys = []; var groupNumber = 1; + _.each(preFilters, function (preFilter) { if (preFilter.attrs && preFilter.attrs.invisible) { return; diff --git a/addons/web/static/tests/views/control_panel_tests.js b/addons/web/static/tests/views/control_panel_tests.js index 08cc1391719..10b1bb79879 100644 --- a/addons/web/static/tests/views/control_panel_tests.js +++ b/addons/web/static/tests/views/control_panel_tests.js @@ -120,6 +120,7 @@ QUnit.module('Views', { assert.deepEqual( controlPanelFactory.loadParams.groups, [[{ + context: {}, description: "Hello", groupNumber: 2, domain: "[]", @@ -198,6 +199,7 @@ QUnit.module('Views', { controlPanelFactory.loadParams.groups, [[ { + "context": {}, "description": "Hello One", "domain": "[]", "groupNumber": 2, @@ -205,6 +207,7 @@ QUnit.module('Views', { "type": "filter" }, { + "context": {}, "description": "Hello Two", "domain": "[('bar', '=', 3)]", "groupNumber": 2, @@ -233,6 +236,7 @@ QUnit.module('Views', { [ [ { + context: {}, description: "Hello One", domain: "[]", groupNumber: 2, @@ -242,6 +246,7 @@ QUnit.module('Views', { ], [ { + context: {}, description: "Hello Two", domain: "[('bar', '=', 3)]", groupNumber: 4, @@ -267,6 +272,7 @@ QUnit.module('Views', { [ [ { + context: {}, description: "Hello", domain: "[]", groupNumber: 2, diff --git a/addons/web/static/tests/views/search_view_tests.js b/addons/web/static/tests/views/search_view_tests.js index fa3fe817c2a..f4b0163ce07 100644 --- a/addons/web/static/tests/views/search_view_tests.js +++ b/addons/web/static/tests/views/search_view_tests.js @@ -2,6 +2,7 @@ odoo.define('web.search_view_tests', function (require) { "use strict"; var FormView = require('web.FormView'); +var ListView = require('web.ListView'); var testUtils = require('web.test_utils'); var createActionManager = testUtils.createActionManager; @@ -694,6 +695,39 @@ QUnit.module('Search View', { window.Date = RealDate; }); + QUnit.test('`context` key in <filter> is used', function (assert) { + assert.expect(3); + + this.archs['partner,4,search'] = '<search>'+ + '<filter string="AAA" name="some_filter" context="{\'coucou_1\': 1}"></filter>' + + '</search>'; + + var actionManager = createActionManager({ + actions: this.actions, + archs: this.archs, + data: this.data, + mockRPC: function (route, args) { + if (route === '/web/dataset/search_read') { + assert.step(JSON.stringify(args.context)); + } + return this._super.apply(this, arguments); + }, + }); + + actionManager.doAction(5); + + // select filter + testUtils.dom.click($('.o_search_options .fa-filter')); + testUtils.dom.click($('.o_menu_item:contains(AAA)')); + + assert.verifySteps([ + "{}", + "{\"coucou_1\":1}", + ]); + + actionManager.destroy(); + }); + QUnit.module('Favorites Menu'); QUnit.test('dynamic filters are saved dynamic', function (assert) { |
