helpdesk_team.py 2.22 KB
Newer Older
1 2 3 4 5 6 7 8 9
from odoo import models, fields, api, _
from odoo.exceptions import UserError

class HelpdeskTeamInherit(models.Model):
    _inherit = 'helpdesk.team'

    helpdesk_ticket_type_id = fields.Many2one('helpdesk.ticket.type','Tipo de ticket',copy=False)
    short_name = fields.Char('Nombre corto',copy=False)
    sequence_id = fields.Many2one('ir.sequence',string="Sequencia",copy=False)
10
    is_support_team = fields.Boolean('Equipo de soporte')
11
    team_admin_id = fields.Many2one('res.users',string="Administrador del equipo")
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

    @api.onchange(short_name)
    def convert_short_name_upper(self):
        if self.short_name:
            name = self.short_name
            self.short_name = name.upper()


    def write(self,vals):
        res = super(HelpdeskTeamInherit, self).write(vals)
        if 'name' in vals:
            self.create_helpdesk_ticket_type()
        if 'short_name' in vals:
            self.create_sequence()
        return res

 
    def copy(self, default=None):
        if default is None:
            default = {}
        if 'name' not in default:
            default['name'] = _("%s (copia)") % self.name
            default['short_name'] = _("%s (copia)") % self.short_name
        return super(HelpdeskTeamInherit, self).copy(default=default)



    @api.model
    def create(self,vals):
        res = super(HelpdeskTeamInherit, self).create(vals)
        res.create_helpdesk_ticket_type()
        res.create_sequence()
        return res


    def create_helpdesk_ticket_type(self):
        if not self.helpdesk_ticket_type_id:
            ticket_type = self.env['helpdesk.ticket.type'].sudo().create({'name':self.name})
            if ticket_type:
                self.helpdesk_ticket_type_id = ticket_type.id
        else:
            self.helpdesk_ticket_type_id.name = self.name


    def create_sequence(self):
        if not self.sequence_id:
            sequence = self.env['ir.sequence'].sudo().create({
                'name': "Helpdesk Ticket sequence "+self.name,
                'code': "helpdesk.ticket."+str(self.id),
                'prefix': self.short_name+"/",
                'padding': 4
            })
            self.sequence_id = sequence.id
        else:
66
            self.sequence_id.prefix = self.short_name+"/"
67 68 69