From a2b2256a1752d4783cf9a0ff9b69b568726e98aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Fri, 12 Jun 2026 16:29:33 +0200 Subject: [PATCH] [IMP] helpdesk_user_default_ticket_team: auto-assign team leader on team change 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. --- helpdesk_user_default_ticket_team/README.rst | 8 ++++++++ .../models/helpdesk_ticket.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/helpdesk_user_default_ticket_team/README.rst b/helpdesk_user_default_ticket_team/README.rst index 13b3f76..0d10945 100644 --- a/helpdesk_user_default_ticket_team/README.rst +++ b/helpdesk_user_default_ticket_team/README.rst @@ -18,6 +18,14 @@ default helpdesk team per user. It provides: * If the assigned team has a default project, the ticket is also linked to that project. +* Automatic user assignment when a team is selected: + + * When a team is set or changed on a ticket, if the current assigned user + is not a member of that team, the team leader (``team_id.user_id``) is + automatically assigned instead. + * If the team has no leader configured, the assigned user is left unchanged + (to avoid creating unassigned tickets). + This is particularly useful for multi-company or multi-team environments where portal users should always have their tickets routed to a specific team. diff --git a/helpdesk_user_default_ticket_team/models/helpdesk_ticket.py b/helpdesk_user_default_ticket_team/models/helpdesk_ticket.py index 7a90d10..dddd1fc 100644 --- a/helpdesk_user_default_ticket_team/models/helpdesk_ticket.py +++ b/helpdesk_user_default_ticket_team/models/helpdesk_ticket.py @@ -4,6 +4,14 @@ 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: