diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-05-13 15:26:12 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-05-13 15:26:12 +0200 |
| commit | 8dd5a85267b522ba569ab9ed44901f95fffbeb4f (patch) | |
| tree | ddb62d1e83e1b810b96c05f6819ca66f8d6b4955 /addons/board/static | |
| parent | 15716642e1975b4f2f29916011a4be29804cda88 (diff) | |
| parent | 60e71302a38b36214efec1213882f573e3ea453c (diff) | |
[MERGE] forward port branch saas-12.3 up to 60e71302a38
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 | 94 |
3 files changed, 102 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 1b3ebc3fc5b..57e98ca87d7 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 953f5d73101..ffdcfbeb7ed 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 db4e76a0749..6a565e68fd1 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', async function (assert) { }); QUnit.test('basic functionality, with one sub action', async function (assert) { - assert.expect(25); + assert.expect(26); var form = await createView({ View: BoardView, @@ -118,7 +118,7 @@ QUnit.test('basic functionality, with one sub action', async 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', async 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'); @@ -687,7 +693,19 @@ QUnit.test('dashboard intercepts custom events triggered by sub controllers', as }); QUnit.test('save actions to dashboard', async 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 = await createActionManager({ data: this.data, @@ -697,6 +715,16 @@ QUnit.test('save actions to dashboard', async 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', @@ -717,12 +745,22 @@ QUnit.test('save actions to dashboard', async function (assert) { assert.containsOnce(actionManager, '.o_list_view', "should display the list view"); + // Sort the list + await testUtils.dom.click($('.o_column_sortable')); + + // Group It + await testUtils.dom.click($('.o_search_options .o_dropdown button:contains(Group By)')); + await testUtils.dom.click($('.o_search_options .o_group_by_menu button')); + await testUtils.dom.click($('.o_search_options .o_group_by_menu button.o_apply_group')); + // add this action to dashboard await testUtils.dom.click($('.o_search_options .o_dropdown button:contains(Favorites)')); await testUtils.dom.click($('.o_add_to_board.o_menu_header')); testUtils.fields.editInput($('input.o_add_to_board_input'), 'a name'); await testUtils.dom.click($('.o_add_to_board_confirm_button')); + testUtils.unpatch(ListController); + actionManager.destroy(); }); @@ -769,6 +807,12 @@ QUnit.test('save two searches to dashboard', async function (assert) { await testUtils.dom.click(actionManager.$('.o_apply_filter')); // Add it to dashboard await testUtils.dom.click(actionManager.$('.o_favorites_menu_button')); + $('.o_search_options .dropdown-menu.o_favorites_menu').one('click', function (ev) { + // This handler is on the webClient + // But since the test suite doesn't have one + // We manually set it here + ev.stopPropagation(); + }); await testUtils.dom.click(actionManager.$('.o_add_to_board')); await testUtils.dom.click(actionManager.$('.o_add_to_board_confirm_button')); // Remove it @@ -781,6 +825,12 @@ QUnit.test('save two searches to dashboard', async function (assert) { await testUtils.dom.click(actionManager.$('.o_apply_filter')); // Add it to dashboard await testUtils.dom.click(actionManager.$('.o_favorites_menu_button')); + $('.o_search_options .dropdown-menu.o_favorites_menu').one('click', function (ev) { + // This handler is on the webClient + // But since the test suite doesn't have one + // We manually set it here + ev.stopPropagation(); + }); await testUtils.dom.click(actionManager.$('.o_add_to_board')); await testUtils.dom.click(actionManager.$('.o_add_to_board_confirm_button')); @@ -912,6 +962,44 @@ QUnit.test("Dashboard should use correct groupby", async function (assert) { form.destroy(); }); +QUnit.test("Dashboard should use correct groupby when defined as a string of one field", async function (assert) { + assert.expect(1); + var form = await 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 === 'web_read_group') { + assert.deepEqual(args.kwargs.groupby, ['bar'], + 'user defined groupby should have precedence on action groupby'); + } + if (route === '/web/action/load') { + return Promise.resolve({ + 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', async function (assert) { assert.expect(3); |
