From 1f55d826c66fe30f1fe40b75830dbd0b439894c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Thu, 5 Sep 2024 12:55:51 +0200 Subject: [PATCH] [IMP] helpdesk_mgmt: Add _default_team_id to team_id field from tickets Related to https://github.com/OCA/helpdesk/pull/553 --- helpdesk_mgmt/models/helpdesk_ticket.py | 7 +++++++ helpdesk_mgmt/tests/test_helpdesk_ticket.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/helpdesk_mgmt/models/helpdesk_ticket.py b/helpdesk_mgmt/models/helpdesk_ticket.py index 57ee374290..f8a49bb022 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket.py +++ b/helpdesk_mgmt/models/helpdesk_ticket.py @@ -22,6 +22,12 @@ def _compute_user_id(self): if not ticket.user_id and ticket.team_id: ticket.user_id = ticket.team_id.alias_user_id + def _default_team_id(self): + user_helpdesk_teams = self.env.user.helpdesk_team_ids + if user_helpdesk_teams: + return fields.first(user_helpdesk_teams).id + return self.env["helpdesk.ticket.team"].search([], limit=1).id + @api.model def _read_group_stage_ids(self, stages, domain, order): """Show always the stages without team, or stages of the default team.""" @@ -101,6 +107,7 @@ def _read_group_stage_ids(self, stages, domain, order): comodel_name="helpdesk.ticket.team", string="Team", index=True, + default=_default_team_id, ) priority = fields.Selection( selection=[ diff --git a/helpdesk_mgmt/tests/test_helpdesk_ticket.py b/helpdesk_mgmt/tests/test_helpdesk_ticket.py index abc4ced815..dd4e1fe188 100644 --- a/helpdesk_mgmt/tests/test_helpdesk_ticket.py +++ b/helpdesk_mgmt/tests/test_helpdesk_ticket.py @@ -1,5 +1,8 @@ import time +from odoo.tests import Form +from odoo.tools import mute_logger + from .common import TestHelpdeskTicketBase @@ -9,6 +12,17 @@ def setUpClass(cls): super().setUpClass() cls.ticket = cls.ticket_a_unassigned + @mute_logger("odoo.models.unlink") + def test_helpdesk_ticket_team_default(self): + helpdesk_form_a = Form(self.env["helpdesk.ticket"].with_user(self.user)) + self.assertEqual(helpdesk_form_a.team_id, self.team_a) + helpdesk_form_b = Form(self.env["helpdesk.ticket"].with_user(self.user_team)) + self.assertEqual(helpdesk_form_b.team_id, self.team_b) + self.team_b.unlink() + first_team = self.env["helpdesk.ticket.team"].search([], limit=1) + helpdesk_form_c = Form(self.env["helpdesk.ticket"].with_user(self.user_team)) + self.assertEqual(helpdesk_form_c.team_id, first_team) + def test_helpdesk_ticket_datetimes(self): old_stage_update = self.ticket.last_stage_update self.assertTrue(