From bcbf4316e669438e9b07c1da744667f689c123f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 19 Jul 2016 13:03:35 +0200 Subject: [PATCH] [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). --- addons/crm/crm_lead.py | 8 ++++---- addons/mail/static/src/js/chat_manager.js | 2 +- .../static/src/js/views/form_relational_widgets.js | 4 ++-- openerp/models.py | 14 ++++++++++---- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index c9064fadfb3..1f9197969c5 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -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): diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js index 40a7388cde7..e3a11b19197 100644 --- a/addons/mail/static/src/js/chat_manager.js +++ b/addons/mail/static/src/js/chat_manager.js @@ -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); }); } diff --git a/addons/web/static/src/js/views/form_relational_widgets.js b/addons/web/static/src/js/views/form_relational_widgets.js index 6274f0bc087..6e565a07a2d 100644 --- a/addons/web/static/src/js/views/form_relational_widgets.js +++ b/addons/web/static/src/js/views/form_relational_widgets.js @@ -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); }); }, diff --git a/openerp/models.py b/openerp/models.py index c92066fd867..76abf29da4a 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -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, }