diff options
| author | Denis Ledoux <dle@odoo.com> | 2019-05-02 09:42:08 +0200 |
|---|---|---|
| committer | Denis Ledoux <dle@odoo.com> | 2019-05-02 09:45:14 +0200 |
| commit | fd0a10026c06315b4fbe520a7a3604a6b395f54a (patch) | |
| tree | 5a7183126ed508303bdab7a31d3691c75e6d9b4a /addons/board/static | |
| parent | 27eb8ba61798e7bc65bb75becc3f89c839a61996 (diff) | |
| parent | b11930047f6652ccf03963c3f18a2a38c502b652 (diff) | |
[MERGE] forward port branch saas-12.1 up to b11930047f6
Diffstat (limited to 'addons/board/static')
| -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 | 3 | ||||
| -rw-r--r-- | addons/board/static/tests/dashboard_tests.js | 82 |
3 files changed, 90 insertions, 7 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 bcfc892213d..9a4970c7092 100644 --- a/addons/board/static/src/js/board_view.js +++ b/addons/board/static/src/js/board_view.js @@ -272,7 +272,8 @@ var BoardRenderer = FormRenderer.extend({ searchQuery: { context: context, domain: domain, - groupBy: context.group_by || [], + groupBy: typeof context.group_by === 'string' && context.group_by ? [context.group_by] : 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..bb0663e1468 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(); }); @@ -911,6 +949,44 @@ QUnit.test("Dashboard should use correct groupby", function (assert) { form.destroy(); }); +QUnit.test("Dashboard should use correct groupby when defined as a string of one field", function (assert) { + assert.expect(1); + var form = createView({ + View: BoardView, + model: 'board', + data: this.data, + arch: '<form string="My Dashboard">' + + '<board style="2-1">' + + '<column>' + + '<action context="{\'group_by\': \'bar\'}" string="ABC" name="51"></action>' + + '</column>' + + '</board>' + + '</form>', + mockRPC: function (route, args) { + if (args.method === 'read_group') { + assert.deepEqual(args.kwargs.groupby, ['bar'], + 'user defined groupby should have precedence on action groupby'); + } + if (route === '/web/action/load') { + return $.when({ + res_model: 'partner', + context: { + group_by: 'some_field', + }, + views: [[4, 'list']], + }); + } + return this._super.apply(this, arguments); + }, + archs: { + 'partner,4,list': + '<list string="Partner"><field name="foo"/></list>', + }, + }); + + form.destroy(); +}); + QUnit.test('click on a cell of pivot view inside dashboard', function (assert) { assert.expect(3); |
