| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- # -*- coding: utf-8 -*-
- from odoo import api, fields, models, Command
- class HelpdeskWorkflowTemplate(models.Model):
- _name = 'helpdesk.workflow.template'
- _description = 'Helpdesk Workflow Template'
- _order = 'sequence, name'
- name = fields.Char(
- string='Template Name',
- required=True,
- translate=True,
- help='Name of the workflow template'
- )
- sequence = fields.Integer(
- string='Sequence',
- default=10,
- help='Order of templates'
- )
- description = fields.Text(
- string='Description',
- translate=True,
- help='Description of the workflow template'
- )
- active = fields.Boolean(
- string='Active',
- default=True,
- help='If unchecked, this template will be hidden'
- )
- stage_template_ids = fields.One2many(
- 'helpdesk.workflow.template.stage',
- 'template_id',
- string='Stages',
- help='Stages included in this workflow template'
- )
- sla_template_ids = fields.One2many(
- 'helpdesk.workflow.template.sla',
- 'template_id',
- string='SLA Policies',
- help='SLA policies included in this workflow template'
- )
- stage_count = fields.Integer(
- string='Stages Count',
- compute='_compute_counts',
- store=False
- )
- sla_count = fields.Integer(
- string='SLA Policies Count',
- compute='_compute_counts',
- store=False
- )
- team_ids = fields.One2many(
- 'helpdesk.team',
- 'workflow_template_id',
- string='Teams Using This Template',
- readonly=True
- )
- team_count = fields.Integer(
- string='Teams Count',
- compute='_compute_counts',
- store=False
- )
- @api.depends('stage_template_ids', 'sla_template_ids', 'team_ids')
- def _compute_counts(self):
- for template in self:
- template.stage_count = len(template.stage_template_ids)
- template.sla_count = len(template.sla_template_ids)
- template.team_count = len(template.team_ids)
- def action_view_teams(self):
- """Open teams using this template"""
- self.ensure_one()
- action = self.env['ir.actions.actions']._for_xml_id('helpdesk.helpdesk_team_action')
- action.update({
- 'domain': [('workflow_template_id', '=', self.id)],
- 'context': {
- 'default_workflow_template_id': self.id,
- 'search_default_workflow_template_id': self.id,
- },
- })
- return action
- def copy_data(self, default=None):
- """Override copy to duplicate stages and SLAs"""
- defaults = super().copy_data(default=default)
- # Note: Stages and SLAs will be copied automatically via ondelete='cascade'
- # We just need to update the name
- for template, vals in zip(self, defaults):
- vals['name'] = self.env._("%s (copy)", template.name)
- return defaults
|