[REF] helpdesk_user_default_ticket_team: extract user assignment into `_define_user_id`
Extract the team-leader assignment logic into a dedicated ``_define_user_id`` helper, shared between ``_compute_user_id`` and ``create``: - ``_compute_user_id`` now delegates to ``_define_user_id`` instead of inlining the membership/leader checks. - ``create`` also assigns ``user_id`` from the default team via the same helper, so a portal-created ticket gets the team leader assigned. This centralises the decision (keep current user / fall back to team leader) in a single, reusable place.
This commit is contained in:
@@ -7,10 +7,10 @@ class HelpdeskTicket(models.Model):
|
|||||||
@api.depends("team_id")
|
@api.depends("team_id")
|
||||||
def _compute_user_id(self):
|
def _compute_user_id(self):
|
||||||
for ticket in self:
|
for ticket in self:
|
||||||
if ticket.team_id:
|
ticket.user_id = self._define_user_id(
|
||||||
if ticket.user_id not in ticket.team_id.user_ids:
|
ticket.team_id,
|
||||||
if ticket.team_id.user_id:
|
ticket.user_id,
|
||||||
ticket.user_id = ticket.team_id.user_id
|
)
|
||||||
|
|
||||||
@api.model_create_multi
|
@api.model_create_multi
|
||||||
def create(self, vals_list):
|
def create(self, vals_list):
|
||||||
@@ -35,4 +35,20 @@ class HelpdeskTicket(models.Model):
|
|||||||
if team.default_project_id:
|
if team.default_project_id:
|
||||||
vals["project_id"] = team.default_project_id.id
|
vals["project_id"] = team.default_project_id.id
|
||||||
|
|
||||||
|
# Set the user_id to which the ticket is assigned
|
||||||
|
user_id = self._define_user_id(team, None)
|
||||||
|
if user_id:
|
||||||
|
vals["user_id"] = user_id.id
|
||||||
return super().create(vals_list)
|
return super().create(vals_list)
|
||||||
|
|
||||||
|
def _define_user_id(self, team_id=None, ticket_user_id=None):
|
||||||
|
if not team_id:
|
||||||
|
return ticket_user_id
|
||||||
|
|
||||||
|
if not ticket_user_id:
|
||||||
|
return team_id.user_id
|
||||||
|
|
||||||
|
if ticket_user_id not in team_id.user_ids:
|
||||||
|
return team_id.user_id
|
||||||
|
|
||||||
|
return ticket_user_id
|
||||||
|
|||||||
Reference in New Issue
Block a user