[FIX] models, mail, *: fix access action crash due to one / multi conversion
get_formview_action and get_formview_id are methods used notably in a redirection called from a mail controller used in notification emails. Those methods however are defined as cr, uid, id and are interpreted as api.one when called by a new-api style method. With modules being converted into the new API, those methods are called as api.one and the result is encapsulated into a list. To avoid having to take the first element of the returned list we decided to simplify the call chain and migrate the methods as multi methods, using ids instead of id. Various addons have been updated accordingly. A temporary support of ids being an int / long has been added to avoid conflict with calls using id (for example if javascript is not updated).
This commit is contained in:
@@ -101,7 +101,7 @@ class crm_lead(FormatAddress, osv.osv):
|
||||
|
||||
def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
|
||||
if context and context.get('opportunity_id'):
|
||||
action = self.get_formview_action(cr, user, context['opportunity_id'], context=context)
|
||||
action = self.get_formview_action(cr, user, [context['opportunity_id']], context=context)
|
||||
if action.get('views') and any(view_id for view_id in action['views'] if view_id[1] == view_type):
|
||||
view_id = next(view_id[0] for view_id in action['views'] if view_id[1] == view_type)
|
||||
res = super(crm_lead, self).fields_view_get(cr, user, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
|
||||
@@ -927,12 +927,12 @@ Update your business card, phone book, social media,... Send an email right now
|
||||
aliases = self.pool['crm.team'].message_get_reply_to(cr, uid, list(team_ids), default=default, context=context)
|
||||
return dict((lead.id, aliases.get(lead.team_id and lead.team_id.id or 0, False)) for lead in leads)
|
||||
|
||||
def get_formview_id(self, cr, uid, id, context=None):
|
||||
obj = self.browse(cr, uid, id, context=context)
|
||||
def get_formview_id(self, cr, uid, ids, context=None):
|
||||
obj = self.browse(cr, uid, ids[0], context=context)
|
||||
if obj.type == 'opportunity':
|
||||
model, view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'crm', 'crm_case_form_view_oppor')
|
||||
else:
|
||||
view_id = super(crm_lead, self).get_formview_id(cr, uid, id, context=context)
|
||||
view_id = super(crm_lead, self).get_formview_id(cr, uid, ids, context=context)
|
||||
return view_id
|
||||
|
||||
def message_get_suggested_recipients(self, cr, uid, ids, context=None):
|
||||
|
||||
@@ -924,7 +924,7 @@ var chat_manager = {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
new Model(res_model).call('get_formview_id', [res_id, session.context]).then(function (view_id) {
|
||||
new Model(res_model).call('get_formview_id', [[res_id], session.context]).then(function (view_id) {
|
||||
redirect_to_document(res_model, res_id, view_id);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ var FieldMany2One = common.AbstractField.extend(common.CompletionFieldMixin, com
|
||||
}
|
||||
var context = self.build_context().eval();
|
||||
var model_obj = new Model(self.field.relation);
|
||||
model_obj.call('get_formview_id', [self.get("value"), context]).then(function(view_id){
|
||||
model_obj.call('get_formview_id', [[self.get("value")], context]).then(function(view_id){
|
||||
var pop = new common.FormViewDialog(self, {
|
||||
res_model: self.field.relation,
|
||||
res_id: self.get("value"),
|
||||
@@ -362,7 +362,7 @@ var FieldMany2One = common.AbstractField.extend(common.CompletionFieldMixin, com
|
||||
execute_formview_action: function() {
|
||||
var self = this;
|
||||
var context = self.build_context().eval();
|
||||
(new Model(self.field.relation)).call('get_formview_action', [self.get("value"), context]).then(function(action) {
|
||||
(new Model(self.field.relation)).call('get_formview_action', [[self.get("value")], context]).then(function(action) {
|
||||
self.do_action(action);
|
||||
});
|
||||
},
|
||||
|
||||
+10
-4
@@ -1696,21 +1696,27 @@ class BaseModel(object):
|
||||
}
|
||||
return result
|
||||
|
||||
def get_formview_id(self, cr, uid, id, context=None):
|
||||
def get_formview_id(self, cr, uid, ids, context=None):
|
||||
""" Return an view id to open the document with. This method is meant to be
|
||||
overridden in addons that want to give specific view ids for example.
|
||||
|
||||
:param int id: id of the document to open
|
||||
"""
|
||||
# TDE CLEANME: temporary workaround for saas-11, to remove in saas-12
|
||||
if isinstance(ids, (int, long)):
|
||||
ids = [ids]
|
||||
return False
|
||||
|
||||
def get_formview_action(self, cr, uid, id, context=None):
|
||||
def get_formview_action(self, cr, uid, ids, context=None):
|
||||
""" Return an action to open the document. This method is meant to be
|
||||
overridden in addons that want to give specific view ids for example.
|
||||
|
||||
:param int id: id of the document to open
|
||||
"""
|
||||
view_id = self.get_formview_id(cr, uid, id, context=context)
|
||||
# TDE CLEANME: temporary workaround for saas-11, to remove in saas-12
|
||||
if isinstance(ids, (int, long)):
|
||||
ids = [ids]
|
||||
view_id = self.get_formview_id(cr, uid, ids, context=context)
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': self._name,
|
||||
@@ -1718,7 +1724,7 @@ class BaseModel(object):
|
||||
'view_mode': 'form',
|
||||
'views': [(view_id, 'form')],
|
||||
'target': 'current',
|
||||
'res_id': id,
|
||||
'res_id': ids[0],
|
||||
'context': context,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user