From e31e207d0ab621846cbdc9f9084c9ba1bdfac7b3 Mon Sep 17 00:00:00 2001 From: Pierrick Brun Date: Thu, 14 Oct 2021 15:47:22 +0200 Subject: [PATCH] [IMP] allow to define default team for a category --- helpdesk_mgmt/models/helpdesk_ticket.py | 7 +++++ .../models/helpdesk_ticket_category.py | 4 +++ .../tests/test_helpdesk_ticket_team.py | 27 +++++++++++++++++++ .../views/helpdesk_ticket_category_views.xml | 1 + 4 files changed, 39 insertions(+) diff --git a/helpdesk_mgmt/models/helpdesk_ticket.py b/helpdesk_mgmt/models/helpdesk_ticket.py index 57ee374290..1d37d24545 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket.py +++ b/helpdesk_mgmt/models/helpdesk_ticket.py @@ -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: @@ -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 # --------------------------------------------------- diff --git a/helpdesk_mgmt/models/helpdesk_ticket_category.py b/helpdesk_mgmt/models/helpdesk_ticket_category.py index f6c93e3067..17718883b8 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket_category.py +++ b/helpdesk_mgmt/models/helpdesk_ticket_category.py @@ -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", + ) diff --git a/helpdesk_mgmt/tests/test_helpdesk_ticket_team.py b/helpdesk_mgmt/tests/test_helpdesk_ticket_team.py index d05b858ddf..b96d51f280 100644 --- a/helpdesk_mgmt/tests/test_helpdesk_ticket_team.py +++ b/helpdesk_mgmt/tests/test_helpdesk_ticket_team.py @@ -73,3 +73,30 @@ 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): + starting_ticket_amount = self.team_a.todo_ticket_count + 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_a.todo_ticket_count, + starting_ticket_amount, + ) + category.default_team_id = self.team_a + self.env["helpdesk.ticket"].create( + { + "name": "Ticket 1", + "description": "Description", + "category_id": category.id, + } + ) + self.assertEqual( + self.team_a.todo_ticket_count, + starting_ticket_amount + 1, + ) diff --git a/helpdesk_mgmt/views/helpdesk_ticket_category_views.xml b/helpdesk_mgmt/views/helpdesk_ticket_category_views.xml index c9195f9d66..c952d79275 100644 --- a/helpdesk_mgmt/views/helpdesk_ticket_category_views.xml +++ b/helpdesk_mgmt/views/helpdesk_ticket_category_views.xml @@ -46,6 +46,7 @@ +