diff options
| author | Lucas Perais (lpe) <lpe@odoo.com> | 2019-04-05 15:59:23 +0000 |
|---|---|---|
| committer | Lucas Perais (lpe) <lpe@odoo.com> | 2019-04-08 14:19:48 +0000 |
| commit | ce3d83f579a2510e8961905d6636db2e9f9cfd53 (patch) | |
| tree | cd702926386a75d113ada8fe8044ff3bbf8fb7a5 | |
| parent | efa90f78e552a980abb54fe70160aac441a0a788 (diff) | |
[FIX] board: correctly fill action context with everything
Several cases:
- on a dashboard viewtype, put a group by on the chart
- on a list viewtype, apply a group by and an ordered by
In both cases the parameters were not taken into account when
rendering the view in the board app
ref: 40dd121938552d3f88289d2e5fcd1d57a0dd01bb
This was because, when saving an action for the board app
we tried to fill the "action's context" with only the contexts of:
- the search query (where context is just one of attributes)
- the ownQueryParams of the controller
Doing that, some other vital attributes, like group_by and orderedBy
where forgotten in the process. "C'est ballot!".
Also, the "real context" of those attributes was saved
as a context within the context.
But (!), the action's context will behave as a "real context" when spawning
views and controllers down the line.
After this commit, we flatten as much as possible all those nested
contexts at the time of saving the view
OPW 1944857
| -rw-r--r-- | addons/board/static/src/js/add_to_board_menu.js | 12 | ||||
| -rw-r--r-- | addons/board/static/src/js/board_view.js | 1 | ||||
| -rw-r--r-- | addons/board/static/tests/dashboard_tests.js | 44 |
3 files changed, 51 insertions, 6 deletions
diff --git a/addons/board/static/src/js/add_to_board_menu.js b/addons/board/static/src/js/add_to_board_menu.js index fb6b469d5ab..ab56287b752 100644 --- a/addons/board/static/src/js/add_to_board_menu.js +++ b/addons/board/static/src/js/add_to_board_menu.js @@ -86,12 +86,18 @@ var AddToBoardMenu = Widget.extend({ var context = new Context(this.action.context); context.add(searchQuery.context); context.add({ - group_by: pyUtils.eval('groupbys', searchQuery.groupBys || []) + group_by: searchQuery.groupBy, + orderedBy: searchQuery.orderedBy, }); this.trigger_up('get_controller_query_params', { - callback: function (controllerContext) { - context.add(controllerContext); + callback: function (controllerQueryParams) { + var queryContext = controllerQueryParams.context; + var allContext = _.extend( + _.omit(controllerQueryParams, ['context']), + queryContext + ); + context.add(allContext); } }); diff --git a/addons/board/static/src/js/board_view.js b/addons/board/static/src/js/board_view.js index 4c1d989f54b..b12f4e9c338 100644 --- a/addons/board/static/src/js/board_view.js +++ b/addons/board/static/src/js/board_view.js @@ -272,6 +272,7 @@ var BoardRenderer = FormRenderer.extend({ context: context, domain: domain, groupBy: context.group_by || [], + orderedBy: context.orderedBy || [], }, withControlPanel: false, }); diff --git a/addons/board/static/tests/dashboard_tests.js b/addons/board/static/tests/dashboard_tests.js index 62dcb1f851c..cd3f47f73fe 100644 --- a/addons/board/static/tests/dashboard_tests.js +++ b/addons/board/static/tests/dashboard_tests.js @@ -109,7 +109,7 @@ QUnit.test('display the no content helper', function (assert) { }); QUnit.test('basic functionality, with one sub action', function (assert) { - assert.expect(25); + assert.expect(26); var form = createView({ View: BoardView, @@ -118,7 +118,7 @@ QUnit.test('basic functionality, with one sub action', function (assert) { arch: '<form string="My Dashboard">' + '<board style="2-1">' + '<column>' + - '<action context="{}" view_mode="list" string="ABC" name="51" domain="[[\'foo\', \'!=\', \'False\']]"></action>' + + '<action context="{"orderedBy": [{"name": "foo", "asc": True}]}" view_mode="list" string="ABC" name="51" domain="[[\'foo\', \'!=\', \'False\']]"></action>' + '</column>' + '</board>' + '</form>', @@ -132,6 +132,12 @@ QUnit.test('basic functionality, with one sub action', function (assert) { } if (route === '/web/dataset/search_read') { assert.deepEqual(args.domain, [['foo', '!=', 'False']], "the domain should be passed"); + assert.deepEqual(args.context.orderedBy, [{ + 'name': 'foo', + 'asc': true, + }], + 'orderedBy is present in the search read when specified on the custom action' + ); } if (route === '/web/view/edit_custom') { assert.step('edit custom'); @@ -686,7 +692,19 @@ QUnit.test('dashboard intercepts custom events triggered by sub controllers', fu }); QUnit.test('save actions to dashboard', function (assert) { - assert.expect(3); + assert.expect(6); + + testUtils.patch(ListController, { + getOwnedQueryParams: function () { + var result = this._super.apply(this, arguments); + result.context = { + 'fire': 'on the bayou', + } + return result; + } + }); + + this.data['partner'].fields.foo.sortable = true; var actionManager = createActionManager({ data: this.data, @@ -696,6 +714,16 @@ QUnit.test('save actions to dashboard', function (assert) { }, mockRPC: function (route, args) { if (route === '/board/add_to_dashboard') { + assert.deepEqual(args.context_to_save.group_by, ['foo'], + 'The group_by should have been saved'); + assert.deepEqual(args.context_to_save.orderedBy, + [{ + name: 'foo', + asc: true, + }], + 'The orderedBy should have been saved'); + assert.strictEqual(args.context_to_save.fire, 'on the bayou', + 'The context of a controller should be passed and flattened'); assert.strictEqual(args.action_id, 1, "should save the correct action"); assert.strictEqual(args.view_mode, 'list', @@ -716,12 +744,22 @@ QUnit.test('save actions to dashboard', function (assert) { assert.containsOnce(actionManager, '.o_list_view', "should display the list view"); + // Sort the list + testUtils.dom.click($('.o_column_sortable')); + + // Group It + testUtils.dom.click($('.o_search_options .o_dropdown button:contains(Group By)')); + testUtils.dom.click($('.o_search_options .o_group_by_menu button')); + testUtils.dom.click($('.o_search_options .o_group_by_menu button.o_apply_group')); + // add this action to dashboard testUtils.dom.click($('.o_search_options .o_dropdown button:contains(Favorites)')); testUtils.dom.click($('.o_add_to_board.o_menu_header')); testUtils.fields.editInput($('input.o_add_to_board_input'), 'a name'); testUtils.dom.click($('.o_add_to_board_confirm_button')); + testUtils.unpatch(ListController); + actionManager.destroy(); }); |
