64 lines
2.4 KiB
Python
64 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.http import request
|
|
|
|
from odoo.addons.mail_plugin.controllers import mail_plugin
|
|
|
|
|
|
class MailPluginController(mail_plugin.MailPluginController):
|
|
|
|
def _get_contact_data(self, partner):
|
|
"""
|
|
Return the tickets key only if the current user can create tickets. So, if they can not
|
|
create tickets, the section won't be visible on the addin side (like if the Helpdesk
|
|
module was not installed on the database).
|
|
"""
|
|
contact_values = super()._get_contact_data(partner)
|
|
|
|
if not request.env['helpdesk.ticket'].has_access('create'):
|
|
return contact_values
|
|
|
|
contact_values['tickets'] = self._fetch_partner_tickets(partner) if partner else []
|
|
|
|
return contact_values
|
|
|
|
def _fetch_partner_tickets(self, partner, offset=0, limit=5):
|
|
"""Returns an array containing partner tickets, each ticket will have the following structure :
|
|
{
|
|
ticket_id: the ticket's id,
|
|
name: the ticket's name,
|
|
fold: True if the ticket has been closed, false otherwise
|
|
}
|
|
"""
|
|
tickets = request.env['helpdesk.ticket'].search([
|
|
('partner_id', '=', partner.id),
|
|
('stage_id.fold', '=', False),
|
|
], offset=offset, limit=limit)
|
|
|
|
if len(tickets) < limit:
|
|
remaining = limit - len(tickets)
|
|
folded_tickets = request.env['helpdesk.ticket'].search([
|
|
('partner_id', '=', partner.id),
|
|
('stage_id.fold', '=', True),
|
|
], limit=remaining)
|
|
tickets |= folded_tickets
|
|
|
|
return [{
|
|
'ticket_id': ticket.id,
|
|
'name': ticket.display_name,
|
|
'fold': ticket.stage_id.fold
|
|
} for ticket in tickets]
|
|
|
|
def _mail_content_logging_models_whitelist(self):
|
|
models_whitelist = super()._mail_content_logging_models_whitelist()
|
|
if not request.env['helpdesk.ticket'].has_access('create'):
|
|
return models_whitelist
|
|
return models_whitelist + ['helpdesk.ticket']
|
|
|
|
def _translation_modules_whitelist(self):
|
|
modules_whitelist = super()._translation_modules_whitelist()
|
|
if not request.env['helpdesk.ticket'].has_access('create'):
|
|
return modules_whitelist
|
|
return modules_whitelist + ['helpdesk_mail_plugin']
|