From 8c1c7ec23e65d8dedfa9400868527850d7a3e88e Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Wed, 11 Jul 2018 14:05:57 +0200 Subject: [FIX] board: open form view of given action It is possible in a dashboard item to open a form view of a record. The view did not take into account the action used to display the item, so for example: from a customer invoice clicking on a record would display the "Vendor Bill" instead of "Customer Invoice" view. With this fix, when a view is being loaded to be displayed in the dashboard, we save a reference to a possible form view and if the form view is displayed, we use this reference. opw-1865454 closes #25718 --- addons/board/static/src/js/dashboard.js | 22 ++++++++++++-- addons/board/static/tests/dashboard_tests.js | 45 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) (limited to 'addons/board/static') diff --git a/addons/board/static/src/js/dashboard.js b/addons/board/static/src/js/dashboard.js index 09c9c4e2559..8a0bb56d1f1 100644 --- a/addons/board/static/src/js/dashboard.js +++ b/addons/board/static/src/js/dashboard.js @@ -117,10 +117,9 @@ FormController.include({ this.do_action({ type: 'ir.actions.act_window', res_model: event.data.model, - views: [[false, 'form']], + views: [[event.data.formViewID || false, 'form']], res_id: event.data.res_id, }); - }, }); @@ -131,6 +130,9 @@ FormRenderer.include({ 'click .oe_dashboard_link_change_layout': '_onChangeLayout', 'click .oe_dashboard_column .oe_close': '_onCloseAction', }), + custom_events: _.extend({}, FormRenderer.prototype.custom_events, { + switch_view: '_onSwitchView', + }), /** * @override @@ -140,6 +142,7 @@ FormRenderer.include({ this.noContentHelp = params.noContentHelp; this.actionsDescr = {}; this._boardSubcontrollers = []; // for board: controllers of subviews + this._boardFormViewIDs = {}; // for board: mapping subview controller to form view id }, /** * Call `on_attach_callback` for each subview @@ -266,6 +269,11 @@ FormRenderer.include({ hasSelectors: false, }); return view.getController(self).then(function (controller) { + self._boardFormViewIDs[controller.handle] = _.first( + _.find(action.views, function (descr) { + return descr[1] === 'form'; + }) + ); self._boardSubcontrollers.push(controller); return controller.appendTo(params.$node); }); @@ -384,6 +392,16 @@ FormRenderer.include({ $action.find('.oe_content').toggle(); this.trigger_up('save_dashboard'); }, + /** + * Let FormController know which form view it should display based on the + * window action of the sub controller that is switching view + * + * @private + * @param {OdooEvent} event + */ + _onSwitchView: function (event) { + event.data.formViewID = this._boardFormViewIDs[event.target.handle]; + }, }); }); diff --git a/addons/board/static/tests/dashboard_tests.js b/addons/board/static/tests/dashboard_tests.js index 505883a5f4b..8d30922fc8b 100644 --- a/addons/board/static/tests/dashboard_tests.js +++ b/addons/board/static/tests/dashboard_tests.js @@ -272,6 +272,51 @@ QUnit.test('can open a record', function (assert) { form.destroy(); }); +QUnit.test('can open record using action form view', function (assert) { + assert.expect(1); + + var form = createView({ + View: FormView, + model: 'board', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '
', + mockRPC: function (route) { + if (route === '/web/action/load') { + return $.when({ + res_model: 'partner', + views: [[4, 'list'], [5, 'form']], + }); + } + return this._super.apply(this, arguments); + }, + archs: { + 'partner,4,list': + '', + 'partner,5,form': + '
', + }, + intercepts: { + do_action: function (event) { + assert.deepEqual(event.data.action, { + res_id: 1, + res_model: 'partner', + type: 'ir.actions.act_window', + views: [[5, 'form']], + }, "should do a do_action with correct parameters"); + }, + }, + }); + + form.$('tr.o_data_row td:contains(yop)').click(); + form.destroy(); +}); + QUnit.test('can drag and drop a view', function (assert) { assert.expect(4); -- cgit v1.2.3