From a1e15b9fced014e58185b161b80eb34692b1474a Mon Sep 17 00:00:00 2001 From: fda-odoo Date: Mon, 16 Oct 2017 17:03:17 +0200 Subject: [PATCH] [FIX] web: use "get_formview_id" when opening record from calendar view Opening a record in a calendar view always showed the default form view when it is not a popup. Example in CRM: opening an opportunity will always show a lead view. The fix aims to use the "get_formview_id" method to find the right id of the view that must be shown instead of using a default id. opw-774272 --- .../js/views/calendar/calendar_controller.js | 21 ++++++++++++------- .../web/static/tests/views/calendar_tests.js | 14 ++++++++++++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/addons/web/static/src/js/views/calendar/calendar_controller.js b/addons/web/static/src/js/views/calendar/calendar_controller.js index 8d27acb43dd..11390793c68 100644 --- a/addons/web/static/src/js/views/calendar/calendar_controller.js +++ b/addons/web/static/src/js/views/calendar/calendar_controller.js @@ -247,13 +247,20 @@ var CalendarController = AbstractController.extend({ id = id && parseInt(id).toString() === id ? parseInt(id) : id; if (!this.eventOpenPopup) { - this.do_action({ - type: 'ir.actions.act_window', - res_id: id, - res_model: this.modelName, - views: [[this.formViewId || false, 'form']], - target: 'current', - context: event.context || self.context, + this._rpc({ + model: self.modelName, + method: 'get_formview_id', + //The event can be called by a view that can have another context than the default one. + args: [[id], event.context || self.context], + }).then(function (viewId) { + self.do_action({ + type:'ir.actions.act_window', + res_id: id, + res_model: self.modelName, + views: [[viewId || false, 'form']], + target: 'current', + context: event.context || self.context, + }); }); return; } diff --git a/addons/web/static/tests/views/calendar_tests.js b/addons/web/static/tests/views/calendar_tests.js index f1caba9ed4a..d40e66317ed 100644 --- a/addons/web/static/tests/views/calendar_tests.js +++ b/addons/web/static/tests/views/calendar_tests.js @@ -975,6 +975,12 @@ QUnit.module('Views', { viewOptions: { initialDate: initialDate, }, + mockRPC: function (route, args) { + if (args.method === "get_formview_id") { + return $.Deferred().resolve('A view'); + } + return this._super(route, args); + }, }); // click on an existing event to open the form view @@ -985,7 +991,7 @@ QUnit.module('Views', { type: "ir.actions.act_window", res_id: 4, res_model: "event", - views: [[false, "form"]], + views: [['A view', "form"]], target: "current", context: {} }, @@ -1103,6 +1109,12 @@ QUnit.module('Views', { viewOptions: { initialDate: initialDate, }, + mockRPC: function (route, args) { + if (args.method === "get_formview_id") { + return $.when(false); + } + return this._super(route, args); + }, }); assert.strictEqual(calendar.$('.fc-resizer').length, 0, "should not have resize button");