In helpdesk_mgmt v16, ``_compute_user_id`` automatically filled ``user_id`` with ``team_id.alias_user_id`` when the team was set and no user was assigned. This behaviour was removed in v18: the compute now only clears ``user_id`` when the assigned user is not a member of the selected team, without assigning anyone in its place. This commit restores equivalent behaviour using ``team_id.user_id`` (the Team Leader field) instead of ``alias_user_id``: - When ``team_id`` changes and the current ``user_id`` is not a member of the new team, the Team Leader is assigned automatically. - If the team has no leader configured, ``user_id`` is left unchanged to avoid creating unassigned tickets. - ``super()`` is not called: this is a full replacement of the v18 OCA behaviour, not an extension of it. Also updates README.rst to document the new auto-assignment behaviour.
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from odoo import api, models
|
|
|
|
|
|
class HelpdeskTicket(models.Model):
|
|
_inherit = "helpdesk.ticket"
|
|
|
|
@api.depends("team_id")
|
|
def _compute_user_id(self):
|
|
for ticket in self:
|
|
if ticket.team_id:
|
|
if ticket.user_id not in ticket.team_id.user_ids:
|
|
if ticket.team_id.user_id:
|
|
ticket.user_id = ticket.team_id.user_id
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals_list):
|
|
for vals in vals_list:
|
|
if not vals.get("team_id") and vals.get("partner_id"):
|
|
# Find the user who creates the ticket
|
|
partner = self.env["res.partner"].browse(vals.get("partner_id"))
|
|
if not partner:
|
|
continue
|
|
user = self.env["res.users"].browse(partner.user_ids[0].id)
|
|
if not user:
|
|
continue
|
|
|
|
# Get its default team_id
|
|
team = user.default_helpdesk_ticket_team_id
|
|
if not team:
|
|
continue
|
|
|
|
vals["team_id"] = team.id
|
|
|
|
# Set the linked project
|
|
if team.default_project_id:
|
|
vals["project_id"] = team.default_project_id.id
|
|
|
|
return super().create(vals_list)
|