Skip to content

Commit

Permalink
[FIX] web: use "get_formview_id" when opening record from calendar view
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fda-odoo committed Oct 17, 2017
1 parent 868e718 commit a1e15b9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
21 changes: 14 additions & 7 deletions addons/web/static/src/js/views/calendar/calendar_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 13 additions & 1 deletion addons/web/static/tests/views/calendar_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: {}
},
Expand Down Expand Up @@ -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");
Expand Down

1 comment on commit a1e15b9

@tde-banana-odoo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using get_formview_action ?

Please sign in to comment.