Skip to content

Commit

Permalink
[IMP] allow to define default team for a category
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierrick Brun authored and PicchiSeba committed Oct 21, 2024
1 parent 41e07ff commit 3509c1d
Show file tree
Hide file tree
Showing 4 changed files with 42 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 @@ -161,6 +161,8 @@ def create(self, vals_list):
vals["number"] = self._prepare_ticket_number(vals)
if vals.get("user_id") and not vals.get("assigned_date"):
vals["assigned_date"] = fields.Datetime.now()
if not vals.get("team_id") and vals.get("category_id"):
vals["team_id"] = self._prepare_team_id(vals)
if vals.get("team_id"):
team = self.env["helpdesk.ticket.team"].browse([vals["team_id"]])
if team.company_id:
Expand Down Expand Up @@ -204,6 +206,11 @@ def _compute_access_url(self):
item.access_url = "/my/ticket/%s" % (item.id)
return res

def _prepare_team_id(self, values):
category = self.env["helpdesk.ticket.category"].browse(values["category_id"])
if category.default_team_id:
return category.default_team_id.id

# ---------------------------------------------------
# Mail gateway
# ---------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions helpdesk_mgmt/models/helpdesk_ticket_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ class HelpdeskCategory(models.Model):
string="Company",
default=lambda self: self.env.company,
)
default_team_id = fields.Many2one(
comodel_name="helpdesk.ticket.team",
string="Default team",
)
30 changes: 30 additions & 0 deletions helpdesk_mgmt/tests/test_helpdesk_ticket_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,33 @@ def test_helpdesk_ticket_todo(self):
2,
"Helpdesk Ticket: Helpdesk ticket team should have two ticket to do.",
)

def test_helpdesk_ticket_team_from_category(self):
self.assertEqual(
self.team_id.todo_ticket_count,
2,
)
category = self.env.ref("helpdesk_mgmt.helpdesk_category_1")
self.env["helpdesk.ticket"].create(
{
"name": "Ticket 1",
"description": "Description",
"category_id": category.id,
}
)
self.assertEqual(
self.team_id.todo_ticket_count,
2,
)
category.default_team_id = self.team_id
self.env["helpdesk.ticket"].create(
{
"name": "Ticket 1",
"description": "Description",
"category_id": category.id,
}
)
self.assertEqual(
self.team_id.todo_ticket_count,
3,
)
1 change: 1 addition & 0 deletions helpdesk_mgmt/views/helpdesk_ticket_category_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
</h1>
</div>
<group name="main">
<field name="default_team_id" />
<field name="company_id" groups="base.group_multi_company" />
<field name="active" invisible="1" />
</group>
Expand Down

0 comments on commit 3509c1d

Please sign in to comment.