In order to be able to identify what action to return based on the access_user. Typically portal users will need to be redirected to the front-end, while internal users will need to be redirected to the back-end.
56 lines
2.2 KiB
Python
56 lines
2.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
from odoo import api, fields, exceptions, models
|
|
|
|
|
|
class Issue(models.Model):
|
|
_name = "project.issue"
|
|
_inherit = ['project.issue']
|
|
|
|
attachment_ids = fields.One2many('ir.attachment', compute='_compute_attachment_ids', string="Main Attachments",
|
|
help="Attachment that don't come from message.")
|
|
website_url = fields.Char('Website URL', compute='_compute_website_url', help='The full URL to access the document through the website.')
|
|
|
|
def _compute_website_url(self):
|
|
for issue in self:
|
|
issue.website_url = '/my/issues/%s' % issue.id
|
|
|
|
def _compute_attachment_ids(self):
|
|
for issue in self:
|
|
attachment_ids = self.env['ir.attachment'].search([('res_id', '=', issue.id), ('res_model', '=', 'project.issue')]).ids
|
|
message_attachment_ids = self.mapped('message_ids.attachment_ids').ids # from mail_thread
|
|
issue.attachment_ids = list(set(attachment_ids) - set(message_attachment_ids))
|
|
|
|
@api.multi
|
|
def get_access_action(self, access_uid=None):
|
|
""" Instead of the classic form view, redirect to website for portal users
|
|
that can read the issue. """
|
|
self.ensure_one()
|
|
user, record = self.env.user, self
|
|
if access_uid:
|
|
user = self.env['res.users'].sudo().browse(access_uid)
|
|
record = self.sudo(user)
|
|
|
|
if user.share:
|
|
try:
|
|
record.check_access_rule('read')
|
|
except exceptions.AccessError:
|
|
pass
|
|
else:
|
|
return {
|
|
'type': 'ir.actions.act_url',
|
|
'url': self.website_url,
|
|
'target': 'self',
|
|
'res_id': self.id,
|
|
}
|
|
return super(Issue, self).get_access_action(access_uid)
|
|
|
|
@api.multi
|
|
def _notification_recipients(self, message, groups):
|
|
groups = super(Issue, self)._notification_recipients(message, groups)
|
|
|
|
for group_name, group_method, group_data in groups:
|
|
group_data['has_button_access'] = True
|
|
|
|
return groups
|