Skip to content

Commit

Permalink
[IMP] helpdesk_mgmt: Add _default_team_id to team_id field from tickets
Browse files Browse the repository at this point in the history
Related to OCA#553
  • Loading branch information
victoralmau committed Sep 5, 2024
1 parent 9ef7dea commit 50ef62c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions helpdesk_mgmt/models/helpdesk_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ def _compute_stage_id(self):
for ticket in self:
ticket.stage_id = ticket.team_id._get_applicable_stages()[:1]

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."""
Expand Down Expand Up @@ -86,6 +92,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=[
Expand Down
1 change: 1 addition & 0 deletions helpdesk_mgmt/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def setUpClass(cls):
"mail_notrack": True,
"no_reset_password": True,
}
cls.company = cls.env.company
cls.user_own = new_test_user(
cls.env,
login="helpdesk_mgmt-user_own",
Expand Down
14 changes: 14 additions & 0 deletions helpdesk_mgmt/tests/test_helpdesk_ticket.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import time

from odoo.tests import Form
from odoo.tools import mute_logger

from .common import TestHelpdeskTicketBase


Expand All @@ -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(
Expand Down

0 comments on commit 50ef62c

Please sign in to comment.