From 6dfcc5f9c85caa8ef67fc0914506c8f0d4f6e4d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 29 Oct 2015 10:54:35 +0100 Subject: [PATCH] [FIX] various: get_access_action form one to multi As this method is overided in several modules, the mix of new and old API makes it difficult to handle. Indeed in some cases we receive the expected dictionary, sometimes in a list, sometimes in a list of list, due to api.one decorator. This is a change in the method API, however it is currently completely buggy. Moreover this method is used internally and should not be used as an external API. Lastly, this method is new from v9. --- addons/mail/controllers/main.py | 2 +- addons/website_blog/models/website_blog.py | 4 ++-- addons/website_forum/models/forum.py | 3 ++- addons/website_portal_sale/models/sale_order.py | 3 ++- addons/website_project_issue/models/project_issue.py | 3 ++- addons/website_quote/models/order.py | 6 +++--- openerp/models.py | 4 ++-- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/addons/mail/controllers/main.py b/addons/mail/controllers/main.py index 7411a4a41aa..f623654dedf 100644 --- a/addons/mail/controllers/main.py +++ b/addons/mail/controllers/main.py @@ -118,7 +118,7 @@ class MailController(http.Controller): if not record_sudo: # record does not seem to exist -> redirect to login return self._redirect_to_messaging() - record_action = record_sudo.get_access_action()[0] + record_action = record_sudo.get_access_action() # the record has an URL redirection: use it directly if record_action['type'] == 'ir.actions.act_url': diff --git a/addons/website_blog/models/website_blog.py b/addons/website_blog/models/website_blog.py index a253871b4b6..49e1e0fbf23 100644 --- a/addons/website_blog/models/website_blog.py +++ b/addons/website_blog/models/website_blog.py @@ -245,10 +245,10 @@ class BlogPost(osv.Model): self._check_for_publication(cr, uid, ids, vals, context=context) return result - def get_access_action(self, cr, uid, id, context=None): + def get_access_action(self, cr, uid, ids, context=None): """ Override method that generated the link to access the document. Instead of the classic form view, redirect to the post on the website directly """ - post = self.browse(cr, uid, id, context=context) + post = self.browse(cr, uid, ids[0], context=context) return { 'type': 'ir.actions.act_url', 'url': '/blog/%s/post/%s' % (post.blog_id.id, post.id), diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py index 0a32498b8ba..1f229d5d200 100644 --- a/addons/website_forum/models/forum.py +++ b/addons/website_forum/models/forum.py @@ -704,10 +704,11 @@ class Post(models.Model): self._cr.execute("""UPDATE forum_post SET views = views+1 WHERE id IN %s""", (self._ids,)) return True - @api.one + @api.multi def get_access_action(self): """ Override method that generated the link to access the document. Instead of the classic form view, redirect to the post on the website directly """ + self.ensure_one() return { 'type': 'ir.actions.act_url', 'url': '/forum/%s/question/%s' % (self.forum_id.id, self.id), diff --git a/addons/website_portal_sale/models/sale_order.py b/addons/website_portal_sale/models/sale_order.py index 3fd896096af..b3d752f2396 100644 --- a/addons/website_portal_sale/models/sale_order.py +++ b/addons/website_portal_sale/models/sale_order.py @@ -7,10 +7,11 @@ from openerp import api, models class sale_order(models.Model): _inherit = 'sale.order' - @api.one + @api.multi def get_access_action(self): """ Override method that generated the link to access the document. Instead of the classic form view, redirect to the online quote if exists. """ + self.ensure_one() if self.state in ['draft', 'cancel']: return super(sale_order, self).get_access_action() return { diff --git a/addons/website_project_issue/models/project_issue.py b/addons/website_project_issue/models/project_issue.py index 9344157422c..90238037a6e 100644 --- a/addons/website_project_issue/models/project_issue.py +++ b/addons/website_project_issue/models/project_issue.py @@ -8,10 +8,11 @@ class Issue(models.Model): _name = "project.issue" _inherit = ['project.issue'] - @api.one + @api.multi def get_access_action(self): """ Override method that generated the link to access the document. Instead of the classic form view, redirect to the post on the website directly """ + self.ensure_one() return { 'type': 'ir.actions.act_url', 'url': '/my/issues/%s' % self.id, diff --git a/addons/website_quote/models/order.py b/addons/website_quote/models/order.py index e87698bf811..016e7eeb410 100644 --- a/addons/website_quote/models/order.py +++ b/addons/website_quote/models/order.py @@ -253,12 +253,12 @@ class sale_order(osv.osv): products += line.product_id.product_tmpl_id.recommended_products(context=context) return products - def get_access_action(self, cr, uid, id, context=None): + def get_access_action(self, cr, uid, ids, context=None): """ Override method that generated the link to access the document. Instead of the classic form view, redirect to the online quote if exists. """ - quote = self.browse(cr, uid, id, context=context) + quote = self.browse(cr, uid, ids[0], context=context) if not quote.template_id: - return super(sale_order, self).get_access_action(cr, uid, id, context=context) + return super(sale_order, self).get_access_action(cr, uid, ids, context=context) return { 'type': 'ir.actions.act_url', 'url': '/quote/%s' % quote.id, diff --git a/openerp/models.py b/openerp/models.py index e785807ef1b..9314e9e51b6 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -1607,14 +1607,14 @@ class BaseModel(object): 'context': context, } - def get_access_action(self, cr, uid, id, context=None): + def get_access_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 access to the document. By default it opens the formview of the document. :param int id: id of the document to open """ - return self.get_formview_action(cr, uid, id, context=context) + return self.get_formview_action(cr, uid, ids[0], context=context) def _view_look_dom_arch(self, cr, uid, node, view_id, context=None): return self.pool['ir.ui.view'].postprocess_and_fields(