From 1e983fc9698ac791e2117978006cb3037c4ee228 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 17 Jan 2024 11:53:50 +0100 Subject: [PATCH 1/3] [FIX] helpdesk_mgmt_project: Don't repeat tests The inheritance should be over the base test class --- helpdesk_mgmt_project/tests/test_helpdesk_ticket.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/helpdesk_mgmt_project/tests/test_helpdesk_ticket.py b/helpdesk_mgmt_project/tests/test_helpdesk_ticket.py index eba4affe20..a51c8c6777 100644 --- a/helpdesk_mgmt_project/tests/test_helpdesk_ticket.py +++ b/helpdesk_mgmt_project/tests/test_helpdesk_ticket.py @@ -1,13 +1,14 @@ -from odoo.addons.helpdesk_mgmt.tests import test_helpdesk_ticket +from odoo.addons.helpdesk_mgmt.tests.common import TestHelpdeskTicketBase -class TestHelpdeskTicketProject(test_helpdesk_ticket.TestHelpdeskTicket): +class TestHelpdeskTicketProject(TestHelpdeskTicketBase): @classmethod def setUpClass(cls): super().setUpClass() Ticket = cls.env["helpdesk.ticket"] Project = cls.env["project.project"] Task = cls.env["project.task"] + cls.ticket = cls.ticket_a_unassigned cls.ticket2 = Ticket.create({"name": "Test 2", "description": "Ticket test2"}) cls.project1 = Project.create({"name": "Test Helpdesk-Project 1"}) cls.task_project1 = Task.create( From bdb646779b947554da3ddc9d251870f9b9643a56 Mon Sep 17 00:00:00 2001 From: Carolina Fernandez Date: Mon, 6 Nov 2023 14:22:50 -0300 Subject: [PATCH 2/3] [IMP] heldespk_mgmt: Helpdesk stages per teams TT45710 --- helpdesk_mgmt/controllers/main.py | 5 +- helpdesk_mgmt/controllers/myaccount.py | 4 +- helpdesk_mgmt/i18n/de.po | 5 ++ helpdesk_mgmt/i18n/en_GB.po | 5 ++ helpdesk_mgmt/i18n/es.po | 5 ++ helpdesk_mgmt/i18n/es_AR.po | 5 ++ helpdesk_mgmt/i18n/fr.po | 5 ++ helpdesk_mgmt/i18n/helpdesk_mgmt.pot | 5 ++ helpdesk_mgmt/i18n/hu.po | 5 ++ helpdesk_mgmt/i18n/it.po | 5 ++ helpdesk_mgmt/i18n/pl.po | 5 ++ helpdesk_mgmt/i18n/pt.po | 5 ++ helpdesk_mgmt/i18n/pt_BR.po | 5 ++ helpdesk_mgmt/i18n/tr.po | 5 ++ helpdesk_mgmt/models/helpdesk_ticket.py | 51 ++++++++++++++++--- helpdesk_mgmt/models/helpdesk_ticket_stage.py | 6 +++ helpdesk_mgmt/models/helpdesk_ticket_team.py | 13 +++++ helpdesk_mgmt/readme/CONTRIBUTORS.rst | 1 + helpdesk_mgmt/static/description/index.html | 1 + helpdesk_mgmt/tests/common.py | 1 + helpdesk_mgmt/tests/test_helpdesk_ticket.py | 42 +++++++++++++++ .../views/helpdesk_ticket_stage_views.xml | 3 ++ 22 files changed, 178 insertions(+), 9 deletions(-) diff --git a/helpdesk_mgmt/controllers/main.py b/helpdesk_mgmt/controllers/main.py index 53056efef6..175c2126d7 100644 --- a/helpdesk_mgmt/controllers/main.py +++ b/helpdesk_mgmt/controllers/main.py @@ -98,7 +98,10 @@ def _prepare_submit_ticket_vals(self, **kw): [("id", "=", int(kw.get("team"))), ("show_in_portal", "=", True)] ) ) - vals.update({"team_id": team.id}) + stage_id = ( + request.env["helpdesk.ticket"].sudo()._get_applicable_stages(team)[0] + ) + vals.update({"team_id": team.id, "stage_id": stage_id.id}) return vals @http.route("/submitted/ticket", type="http", auth="user", website=True, csrf=True) diff --git a/helpdesk_mgmt/controllers/myaccount.py b/helpdesk_mgmt/controllers/myaccount.py index 1eca8c0109..2db3e0ca99 100644 --- a/helpdesk_mgmt/controllers/myaccount.py +++ b/helpdesk_mgmt/controllers/myaccount.py @@ -182,8 +182,8 @@ def portal_my_ticket(self, ticket_id, access_token=None, **kw): return request.render("helpdesk_mgmt.portal_helpdesk_ticket_page", values) def _ticket_get_page_view_values(self, ticket, access_token, **kwargs): - closed_stages = request.env["helpdesk.ticket.stage"].search( - [("close_from_portal", "=", True)] + closed_stages = ticket._get_applicable_stages(ticket.team_id).filtered( + lambda s: s.close_from_portal ) values = { "closed_stages": closed_stages, # used to display close buttons diff --git a/helpdesk_mgmt/i18n/de.po b/helpdesk_mgmt/i18n/de.po index 8c8cb1e167..0ed3227269 100644 --- a/helpdesk_mgmt/i18n/de.po +++ b/helpdesk_mgmt/i18n/de.po @@ -729,6 +729,11 @@ msgstr "Helpdesk Teamsuche" msgid "Helpdesk Team name..." msgstr "Helpdesk Teamname..." +#. module: helpdesk_mgmt +#: model:ir.model.fields,field_description:helpdesk_mgmt.field_helpdesk_ticket_stage__team_ids +msgid "Helpdesk Teams" +msgstr "" + #. module: helpdesk_mgmt #: model:ir.actions.act_window,name:helpdesk_mgmt.action_helpdesk_ticket_kanban_from_dashboard #: model:ir.model,name:helpdesk_mgmt.model_helpdesk_ticket diff --git a/helpdesk_mgmt/i18n/en_GB.po b/helpdesk_mgmt/i18n/en_GB.po index 285adea57c..94783ebb84 100644 --- a/helpdesk_mgmt/i18n/en_GB.po +++ b/helpdesk_mgmt/i18n/en_GB.po @@ -719,6 +719,11 @@ msgstr "" msgid "Helpdesk Team name..." msgstr "" +#. module: helpdesk_mgmt +#: model:ir.model.fields,field_description:helpdesk_mgmt.field_helpdesk_ticket_stage__team_ids +msgid "Helpdesk Teams" +msgstr "" + #. module: helpdesk_mgmt #: model:ir.actions.act_window,name:helpdesk_mgmt.action_helpdesk_ticket_kanban_from_dashboard #: model:ir.model,name:helpdesk_mgmt.model_helpdesk_ticket diff --git a/helpdesk_mgmt/i18n/es.po b/helpdesk_mgmt/i18n/es.po index 3ca9dca8ff..bb8af4aa0c 100644 --- a/helpdesk_mgmt/i18n/es.po +++ b/helpdesk_mgmt/i18n/es.po @@ -866,6 +866,11 @@ msgstr "Buscar equipo del servicio de asistencia" msgid "Helpdesk Team name..." msgstr "Nombre del equipo..." +#. module: helpdesk_mgmt +#: model:ir.model.fields,field_description:helpdesk_mgmt.field_helpdesk_ticket_stage__team_ids +msgid "Helpdesk Teams" +msgstr "Equipos del servicio de asistencia" + #. module: helpdesk_mgmt #: model:ir.actions.act_window,name:helpdesk_mgmt.action_helpdesk_ticket_kanban_from_dashboard #: model:ir.model,name:helpdesk_mgmt.model_helpdesk_ticket diff --git a/helpdesk_mgmt/i18n/es_AR.po b/helpdesk_mgmt/i18n/es_AR.po index 9856c0c203..493575d0fd 100644 --- a/helpdesk_mgmt/i18n/es_AR.po +++ b/helpdesk_mgmt/i18n/es_AR.po @@ -859,6 +859,11 @@ msgstr "Buscar Equipo de Mesa de Ayuda" msgid "Helpdesk Team name..." msgstr "Nombre del equipo..." +#. module: helpdesk_mgmt +#: model:ir.model.fields,field_description:helpdesk_mgmt.field_helpdesk_ticket_stage__team_ids +msgid "Helpdesk Teams" +msgstr "Equipos de la Mesa de Ayuda" + #. module: helpdesk_mgmt #: model:ir.actions.act_window,name:helpdesk_mgmt.action_helpdesk_ticket_kanban_from_dashboard #: model:ir.model,name:helpdesk_mgmt.model_helpdesk_ticket diff --git a/helpdesk_mgmt/i18n/fr.po b/helpdesk_mgmt/i18n/fr.po index 19e651023e..8b5d1b44a1 100644 --- a/helpdesk_mgmt/i18n/fr.po +++ b/helpdesk_mgmt/i18n/fr.po @@ -732,6 +732,11 @@ msgstr "Recherche d'équipe d'assistance" msgid "Helpdesk Team name..." msgstr "Nom de l'équipe d'assistance ..." +#. module: helpdesk_mgmt +#: model:ir.model.fields,field_description:helpdesk_mgmt.field_helpdesk_ticket_stage__team_ids +msgid "Helpdesk Teams" +msgstr "" + #. module: helpdesk_mgmt #: model:ir.actions.act_window,name:helpdesk_mgmt.action_helpdesk_ticket_kanban_from_dashboard #: model:ir.model,name:helpdesk_mgmt.model_helpdesk_ticket diff --git a/helpdesk_mgmt/i18n/helpdesk_mgmt.pot b/helpdesk_mgmt/i18n/helpdesk_mgmt.pot index 58d22aa08c..02a27a5754 100644 --- a/helpdesk_mgmt/i18n/helpdesk_mgmt.pot +++ b/helpdesk_mgmt/i18n/helpdesk_mgmt.pot @@ -685,6 +685,11 @@ msgstr "" msgid "Helpdesk Team name..." msgstr "" +#. module: helpdesk_mgmt +#: model:ir.model.fields,field_description:helpdesk_mgmt.field_helpdesk_ticket_stage__team_ids +msgid "Helpdesk Teams" +msgstr "" + #. module: helpdesk_mgmt #: model:ir.actions.act_window,name:helpdesk_mgmt.action_helpdesk_ticket_kanban_from_dashboard #: model:ir.model,name:helpdesk_mgmt.model_helpdesk_ticket diff --git a/helpdesk_mgmt/i18n/hu.po b/helpdesk_mgmt/i18n/hu.po index 0879a3f0f5..a738d20d41 100644 --- a/helpdesk_mgmt/i18n/hu.po +++ b/helpdesk_mgmt/i18n/hu.po @@ -723,6 +723,11 @@ msgstr "Csapat keresés" msgid "Helpdesk Team name..." msgstr "Csapat neve..." +#. module: helpdesk_mgmt +#: model:ir.model.fields,field_description:helpdesk_mgmt.field_helpdesk_ticket_stage__team_ids +msgid "Helpdesk Teams" +msgstr "" + #. module: helpdesk_mgmt #: model:ir.actions.act_window,name:helpdesk_mgmt.action_helpdesk_ticket_kanban_from_dashboard #: model:ir.model,name:helpdesk_mgmt.model_helpdesk_ticket diff --git a/helpdesk_mgmt/i18n/it.po b/helpdesk_mgmt/i18n/it.po index 0e41d314b0..198c3fb287 100644 --- a/helpdesk_mgmt/i18n/it.po +++ b/helpdesk_mgmt/i18n/it.po @@ -725,6 +725,11 @@ msgstr "Cerca team Helpdesk" msgid "Helpdesk Team name..." msgstr "Nome team Helpdesk..." +#. module: helpdesk_mgmt +#: model:ir.model.fields,field_description:helpdesk_mgmt.field_helpdesk_ticket_stage__team_ids +msgid "Helpdesk Teams" +msgstr "" + #. module: helpdesk_mgmt #: model:ir.actions.act_window,name:helpdesk_mgmt.action_helpdesk_ticket_kanban_from_dashboard #: model:ir.model,name:helpdesk_mgmt.model_helpdesk_ticket diff --git a/helpdesk_mgmt/i18n/pl.po b/helpdesk_mgmt/i18n/pl.po index bfb1e0607b..62a8ab3187 100644 --- a/helpdesk_mgmt/i18n/pl.po +++ b/helpdesk_mgmt/i18n/pl.po @@ -722,6 +722,11 @@ msgstr "" msgid "Helpdesk Team name..." msgstr "" +#. module: helpdesk_mgmt +#: model:ir.model.fields,field_description:helpdesk_mgmt.field_helpdesk_ticket_stage__team_ids +msgid "Helpdesk Teams" +msgstr "" + #. module: helpdesk_mgmt #: model:ir.actions.act_window,name:helpdesk_mgmt.action_helpdesk_ticket_kanban_from_dashboard #: model:ir.model,name:helpdesk_mgmt.model_helpdesk_ticket diff --git a/helpdesk_mgmt/i18n/pt.po b/helpdesk_mgmt/i18n/pt.po index f849ea8bb7..2ef32ffd40 100644 --- a/helpdesk_mgmt/i18n/pt.po +++ b/helpdesk_mgmt/i18n/pt.po @@ -727,6 +727,11 @@ msgstr "Pesquisar na Equipa de Helpdesk" msgid "Helpdesk Team name..." msgstr "Nome da Equipe de helpdesk..." +#. module: helpdesk_mgmt +#: model:ir.model.fields,field_description:helpdesk_mgmt.field_helpdesk_ticket_stage__team_ids +msgid "Helpdesk Teams" +msgstr "" + #. module: helpdesk_mgmt #: model:ir.actions.act_window,name:helpdesk_mgmt.action_helpdesk_ticket_kanban_from_dashboard #: model:ir.model,name:helpdesk_mgmt.model_helpdesk_ticket diff --git a/helpdesk_mgmt/i18n/pt_BR.po b/helpdesk_mgmt/i18n/pt_BR.po index 1d7682c015..8f939ce363 100644 --- a/helpdesk_mgmt/i18n/pt_BR.po +++ b/helpdesk_mgmt/i18n/pt_BR.po @@ -729,6 +729,11 @@ msgstr "Buscar em Equipe de Atendimento" msgid "Helpdesk Team name..." msgstr "Buscar em Equipe de Atendimento" +#. module: helpdesk_mgmt +#: model:ir.model.fields,field_description:helpdesk_mgmt.field_helpdesk_ticket_stage__team_ids +msgid "Helpdesk Teams" +msgstr "" + #. module: helpdesk_mgmt #: model:ir.actions.act_window,name:helpdesk_mgmt.action_helpdesk_ticket_kanban_from_dashboard #: model:ir.model,name:helpdesk_mgmt.model_helpdesk_ticket diff --git a/helpdesk_mgmt/i18n/tr.po b/helpdesk_mgmt/i18n/tr.po index bde8ea55be..e1e7964c62 100644 --- a/helpdesk_mgmt/i18n/tr.po +++ b/helpdesk_mgmt/i18n/tr.po @@ -730,6 +730,11 @@ msgstr "Yardım Masası Ekibi Arama" msgid "Helpdesk Team name..." msgstr "Yardım Masası Ekip adı..." +#. module: helpdesk_mgmt +#: model:ir.model.fields,field_description:helpdesk_mgmt.field_helpdesk_ticket_stage__team_ids +msgid "Helpdesk Teams" +msgstr "" + #. module: helpdesk_mgmt #: model:ir.actions.act_window,name:helpdesk_mgmt.action_helpdesk_ticket_kanban_from_dashboard #: model:ir.model,name:helpdesk_mgmt.model_helpdesk_ticket diff --git a/helpdesk_mgmt/models/helpdesk_ticket.py b/helpdesk_mgmt/models/helpdesk_ticket.py index b8c8a3669d..17ef106e45 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket.py +++ b/helpdesk_mgmt/models/helpdesk_ticket.py @@ -10,13 +10,41 @@ class HelpdeskTicket(models.Model): _mail_post_access = "read" _inherit = ["mail.thread.cc", "mail.activity.mixin", "portal.mixin"] + def _get_applicable_stages(self, team): + if team: + return team._determine_stages()[team.id] + else: + return self.env["helpdesk.ticket.stage"].search([("team_ids", "=", False)]) + def _get_default_stage_id(self): - return self.env["helpdesk.ticket.stage"].search([], limit=1).id + return self._get_applicable_stages(self.team_id)[:1] + + @api.depends("team_id") + def _compute_stage_id(self): + for ticket in self: + ticket.stage_id = self._get_applicable_stages(ticket.team_id)[:1] + + def _default_team_id(self): + team_id = ( + self.env["helpdesk.ticket.team"] + .search([("user_ids", "in", self.env.uid)], limit=1) + .id + ) + if not team_id: + team_id = self.env["helpdesk.ticket.team"].search([], limit=1).id + return team_id @api.model def _read_group_stage_ids(self, stages, domain, order): - stage_ids = self.env["helpdesk.ticket.stage"].search([]) - return stage_ids + search_domain = [("id", "in", stages.ids)] + if self.env.context.get("default_team_id"): + search_domain = [ + "|", + "|", + ("team_ids", "=", False), + ("team_ids", "in", self.env.context["default_team_id"]), + ] + search_domain + return stages.search(search_domain, order=order) number = fields.Char(string="Ticket number", default="/", readonly=True) name = fields.Char(string="Title", required=True) @@ -31,16 +59,22 @@ def _read_group_stage_ids(self, stages, domain, order): user_ids = fields.Many2many( comodel_name="res.users", related="team_id.user_ids", string="Users" ) + stage_id = fields.Many2one( comodel_name="helpdesk.ticket.stage", string="Stage", - group_expand="_read_group_stage_ids", + compute="_compute_stage_id", default=_get_default_stage_id, - tracking=True, + store=True, + readonly=False, ondelete="restrict", - index=True, + tracking=True, + group_expand="_read_group_stage_ids", copy=False, + index=True, + domain="['|',('team_ids', '=', team_id),('team_ids','=',False)]", ) + partner_id = fields.Many2one(comodel_name="res.partner", string="Contact") partner_name = fields.Char() partner_email = fields.Char(string="Email") @@ -70,6 +104,8 @@ def _read_group_stage_ids(self, stages, domain, order): team_id = fields.Many2one( comodel_name="helpdesk.ticket.team", string="Team", + default=_default_team_id, + index=True, ) priority = fields.Selection( selection=[ @@ -130,6 +166,9 @@ 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 vals.get("team_id"): + team = self.env["helpdesk.ticket.team"].browse(vals["team_id"]) + vals["stage_id"] = team._determine_stages()[team.id][0].id return super().create(vals_list) def copy(self, default=None): diff --git a/helpdesk_mgmt/models/helpdesk_ticket_stage.py b/helpdesk_mgmt/models/helpdesk_ticket_stage.py index 7d1fc7e469..e220b5b5e6 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket_stage.py +++ b/helpdesk_mgmt/models/helpdesk_ticket_stage.py @@ -35,6 +35,12 @@ class HelpdeskTicketStage(models.Model): string="Company", default=lambda self: self.env.company, ) + team_ids = fields.Many2many( + comodel_name="helpdesk.ticket.team", + relation="team_stage_rel", + string="Helpdesk Teams", + help="Specific team that uses this stage. If it is empty all teams could uses", + ) @api.onchange("closed") def _onchange_closed(self): diff --git a/helpdesk_mgmt/models/helpdesk_ticket_team.py b/helpdesk_mgmt/models/helpdesk_ticket_team.py index 7f141d33eb..a3caa0bb9e 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket_team.py +++ b/helpdesk_mgmt/models/helpdesk_ticket_team.py @@ -67,6 +67,19 @@ class HelpdeskTeam(models.Model): help="Allow to select this team when creating a new ticket in the portal.", ) + def _determine_stages(self): + """Get a dict with the stage per team that should be set as first to a created ticket + :returns a mapping of team identifier with the stage. + :rtype : dict (key=team_id, value=record of helpdesk.ticket.stage) + """ + result = dict.fromkeys(self.ids, self.env["helpdesk.ticket.stage"]) + for team in self: + result[team.id] = self.env["helpdesk.ticket.stage"].search( + ["|", ("team_ids", "=", False), ("team_ids", "in", team.id)], + order="sequence", + ) + return result + @api.depends("ticket_ids", "ticket_ids.stage_id") def _compute_todo_tickets(self): ticket_model = self.env["helpdesk.ticket"] diff --git a/helpdesk_mgmt/readme/CONTRIBUTORS.rst b/helpdesk_mgmt/readme/CONTRIBUTORS.rst index 15e2effd37..5b4696871e 100644 --- a/helpdesk_mgmt/readme/CONTRIBUTORS.rst +++ b/helpdesk_mgmt/readme/CONTRIBUTORS.rst @@ -27,6 +27,7 @@ * Pedro M. Baeza * Víctor Martínez + * Carolina Fernandez * `ID42 Sistemas `_: diff --git a/helpdesk_mgmt/static/description/index.html b/helpdesk_mgmt/static/description/index.html index 159c885b70..b1ee4f4a6c 100644 --- a/helpdesk_mgmt/static/description/index.html +++ b/helpdesk_mgmt/static/description/index.html @@ -568,6 +568,7 @@

Contributors

  • Tecnativa:
    • Pedro M. Baeza
    • Víctor Martínez
    • +
    • Carolina Fernandez
  • ID42 Sistemas:
      diff --git a/helpdesk_mgmt/tests/common.py b/helpdesk_mgmt/tests/common.py index f2f58ce4f1..565698179f 100644 --- a/helpdesk_mgmt/tests/common.py +++ b/helpdesk_mgmt/tests/common.py @@ -39,6 +39,7 @@ def setUpClass(cls): cls.team_b = helpdesk_ticket_team.create( {"name": "Team B", "user_ids": [(6, 0, [cls.user_team.id])]} ) + cls.new_stage = cls.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_new") cls.ticket_a_unassigned = cls._create_ticket(cls, cls.team_a) cls.ticket_a_unassigned.priority = "3" cls.ticket_a_user_own = cls._create_ticket(cls, cls.team_a, cls.user_own) diff --git a/helpdesk_mgmt/tests/test_helpdesk_ticket.py b/helpdesk_mgmt/tests/test_helpdesk_ticket.py index 2f1dc8f0c6..bc5c3334f1 100644 --- a/helpdesk_mgmt/tests/test_helpdesk_ticket.py +++ b/helpdesk_mgmt/tests/test_helpdesk_ticket.py @@ -97,3 +97,45 @@ def test_helpdesk_ticket_message_new(self): self.assertEqual( t.name, title, "The ticket should have the correct (new) title." ) + + def test_ticket_with_team_stage(self): + self.new_stage.team_ids = [(6, 0, [self.team_a.id, self.team_b.id])] + in_progress_stage = self.env.ref( + "helpdesk_mgmt.helpdesk_ticket_stage_in_progress" + ) + in_progress_stage.team_ids = [(6, 0, [self.team_b.id])] + new_ticket = self.env["helpdesk.ticket"].create( + { + "name": "New Ticket", + "description": "Description", + "team_id": self.team_a.id, + "user_id": self.user.id, + "priority": "1", + } + ) + self.assertEqual(new_ticket.stage_id, self.new_stage) + self.new_stage.team_ids = [(6, 0, [self.team_a.id])] + new_ticket.team_id = self.team_b + self.assertEqual(new_ticket.stage_id, in_progress_stage) + self.new_stage.team_ids = False + new_ticket.team_id = False + self.assertEqual(new_ticket.stage_id, self.new_stage) + + def test_ticket_without_team_stage(self): + self.new_stage.team_ids = False + self.assertEqual( + self.ticket.stage_id, self.team_a._determine_stages()[self.team_a.id][0] + ) + self.assertEqual(self.ticket.stage_id, self.new_stage) + + def test_ticket_without_team(self): + new_ticket = self.env["helpdesk.ticket"].create( + { + "name": "New Ticket", + "description": "Description", + "team_id": False, + "user_id": self.user.id, + "priority": "1", + } + ) + self.assertEqual(self.new_stage, new_ticket.stage_id) diff --git a/helpdesk_mgmt/views/helpdesk_ticket_stage_views.xml b/helpdesk_mgmt/views/helpdesk_ticket_stage_views.xml index 2077034bf7..b1117c0181 100644 --- a/helpdesk_mgmt/views/helpdesk_ticket_stage_views.xml +++ b/helpdesk_mgmt/views/helpdesk_ticket_stage_views.xml @@ -12,6 +12,7 @@ /> + + + Date: Tue, 16 Jan 2024 18:54:50 +0100 Subject: [PATCH 3/3] [IMP] helpdesk_mgmt: Simplify logic - Remove default - Centralize method for determining applicable stages - Make compatible with multi-company --- helpdesk_mgmt/README.rst | 3 +- helpdesk_mgmt/controllers/main.py | 23 ++++------ helpdesk_mgmt/controllers/myaccount.py | 2 +- helpdesk_mgmt/models/helpdesk_ticket.py | 43 +++++-------------- helpdesk_mgmt/models/helpdesk_ticket_stage.py | 1 + helpdesk_mgmt/models/helpdesk_ticket_team.py | 27 ++++++------ helpdesk_mgmt/static/description/index.html | 2 +- helpdesk_mgmt/tests/test_helpdesk_ticket.py | 8 ---- 8 files changed, 38 insertions(+), 71 deletions(-) diff --git a/helpdesk_mgmt/README.rst b/helpdesk_mgmt/README.rst index 2f00a2cb67..56c09306b6 100644 --- a/helpdesk_mgmt/README.rst +++ b/helpdesk_mgmt/README.rst @@ -7,7 +7,7 @@ Helpdesk Management !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:37cc770b0537354407fedcbe0d568ba9bdd6aa460144a7af475c60ae3f91ad27 + !! source digest: sha256:a417b3ef325ea73b03c6c64e0476702e5a35949224072491138ce827feb4d6e7 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -214,6 +214,7 @@ Contributors * Pedro M. Baeza * Víctor Martínez + * Carolina Fernandez * `ID42 Sistemas `_: diff --git a/helpdesk_mgmt/controllers/main.py b/helpdesk_mgmt/controllers/main.py index 175c2126d7..aa74f50d54 100644 --- a/helpdesk_mgmt/controllers/main.py +++ b/helpdesk_mgmt/controllers/main.py @@ -70,26 +70,21 @@ def _prepare_submit_ticket_vals(self, **kw): category = http.request.env["helpdesk.ticket.category"].browse( int(kw.get("category")) ) - company = category.company_id or http.request.env.user.company_id + company = category.company_id or http.request.env.company vals = { "company_id": company.id, "category_id": category.id, "description": plaintext2html(kw.get("description")), "name": kw.get("subject"), "attachment_ids": False, - "channel_id": request.env["helpdesk.ticket.channel"] - .sudo() - .search([("name", "=", "Web")]) - .id, + "channel_id": request.env.ref( + "helpdesk_mgmt.helpdesk_ticket_channel_web", False + ).id, "partner_id": request.env.user.partner_id.id, "partner_name": request.env.user.partner_id.name, "partner_email": request.env.user.partner_id.email, - # Need to set stage_id so that the _track_template() method is called - # and the mail is sent automatically if applicable - "stage_id": request.env["helpdesk.ticket"] - .with_company(company.id) - .default_get(["stage_id"])["stage_id"], } + team = http.request.env["helpdesk.ticket.team"] if company.helpdesk_mgmt_portal_select_team and kw.get("team"): team = ( http.request.env["helpdesk.ticket.team"] @@ -98,10 +93,10 @@ def _prepare_submit_ticket_vals(self, **kw): [("id", "=", int(kw.get("team"))), ("show_in_portal", "=", True)] ) ) - stage_id = ( - request.env["helpdesk.ticket"].sudo()._get_applicable_stages(team)[0] - ) - vals.update({"team_id": team.id, "stage_id": stage_id.id}) + vals["team_id"] = team.id + # Need to set stage_id so that the _track_template() method is called + # and the mail is sent automatically if applicable + vals["stage_id"] = team._get_applicable_stages()[:1].id return vals @http.route("/submitted/ticket", type="http", auth="user", website=True, csrf=True) diff --git a/helpdesk_mgmt/controllers/myaccount.py b/helpdesk_mgmt/controllers/myaccount.py index 2db3e0ca99..b5b8a4bdaf 100644 --- a/helpdesk_mgmt/controllers/myaccount.py +++ b/helpdesk_mgmt/controllers/myaccount.py @@ -182,7 +182,7 @@ def portal_my_ticket(self, ticket_id, access_token=None, **kw): return request.render("helpdesk_mgmt.portal_helpdesk_ticket_page", values) def _ticket_get_page_view_values(self, ticket, access_token, **kwargs): - closed_stages = ticket._get_applicable_stages(ticket.team_id).filtered( + closed_stages = ticket.team_id._get_applicable_stages().filtered( lambda s: s.close_from_portal ) values = { diff --git a/helpdesk_mgmt/models/helpdesk_ticket.py b/helpdesk_mgmt/models/helpdesk_ticket.py index 17ef106e45..a843d63851 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket.py +++ b/helpdesk_mgmt/models/helpdesk_ticket.py @@ -10,39 +10,24 @@ class HelpdeskTicket(models.Model): _mail_post_access = "read" _inherit = ["mail.thread.cc", "mail.activity.mixin", "portal.mixin"] - def _get_applicable_stages(self, team): - if team: - return team._determine_stages()[team.id] - else: - return self.env["helpdesk.ticket.stage"].search([("team_ids", "=", False)]) - - def _get_default_stage_id(self): - return self._get_applicable_stages(self.team_id)[:1] - @api.depends("team_id") def _compute_stage_id(self): for ticket in self: - ticket.stage_id = self._get_applicable_stages(ticket.team_id)[:1] - - def _default_team_id(self): - team_id = ( - self.env["helpdesk.ticket.team"] - .search([("user_ids", "in", self.env.uid)], limit=1) - .id - ) - if not team_id: - team_id = self.env["helpdesk.ticket.team"].search([], limit=1).id - return team_id + ticket.stage_id = ticket.team_id._get_applicable_stages()[:1] @api.model def _read_group_stage_ids(self, stages, domain, order): - search_domain = [("id", "in", stages.ids)] - if self.env.context.get("default_team_id"): + """Show always the stages without team, or stages of the default team.""" + search_domain = [ + "|", + ("id", "in", stages.ids), + ("team_ids", "=", False), + ] + default_team_id = self.default_get(["team_id"])["team_id"] + if default_team_id: search_domain = [ "|", - "|", - ("team_ids", "=", False), - ("team_ids", "in", self.env.context["default_team_id"]), + ("team_ids", "=", default_team_id), ] + search_domain return stages.search(search_domain, order=order) @@ -59,12 +44,10 @@ def _read_group_stage_ids(self, stages, domain, order): user_ids = fields.Many2many( comodel_name="res.users", related="team_id.user_ids", string="Users" ) - stage_id = fields.Many2one( comodel_name="helpdesk.ticket.stage", string="Stage", compute="_compute_stage_id", - default=_get_default_stage_id, store=True, readonly=False, ondelete="restrict", @@ -74,11 +57,9 @@ def _read_group_stage_ids(self, stages, domain, order): index=True, domain="['|',('team_ids', '=', team_id),('team_ids','=',False)]", ) - partner_id = fields.Many2one(comodel_name="res.partner", string="Contact") partner_name = fields.Char() partner_email = fields.Char(string="Email") - last_stage_update = fields.Datetime(default=fields.Datetime.now) assigned_date = fields.Datetime() closed_date = fields.Datetime() @@ -104,7 +85,6 @@ def _read_group_stage_ids(self, stages, domain, order): team_id = fields.Many2one( comodel_name="helpdesk.ticket.team", string="Team", - default=_default_team_id, index=True, ) priority = fields.Selection( @@ -166,9 +146,6 @@ 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 vals.get("team_id"): - team = self.env["helpdesk.ticket.team"].browse(vals["team_id"]) - vals["stage_id"] = team._determine_stages()[team.id][0].id return super().create(vals_list) def copy(self, default=None): diff --git a/helpdesk_mgmt/models/helpdesk_ticket_stage.py b/helpdesk_mgmt/models/helpdesk_ticket_stage.py index e220b5b5e6..6686712563 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket_stage.py +++ b/helpdesk_mgmt/models/helpdesk_ticket_stage.py @@ -40,6 +40,7 @@ class HelpdeskTicketStage(models.Model): relation="team_stage_rel", string="Helpdesk Teams", help="Specific team that uses this stage. If it is empty all teams could uses", + domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", ) @api.onchange("closed") diff --git a/helpdesk_mgmt/models/helpdesk_ticket_team.py b/helpdesk_mgmt/models/helpdesk_ticket_team.py index a3caa0bb9e..75df44609b 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket_team.py +++ b/helpdesk_mgmt/models/helpdesk_ticket_team.py @@ -48,7 +48,6 @@ class HelpdeskTeam(models.Model): inverse_name="team_id", string="Tickets", ) - todo_ticket_count = fields.Integer( string="Number of tickets", compute="_compute_todo_tickets" ) @@ -67,18 +66,20 @@ class HelpdeskTeam(models.Model): help="Allow to select this team when creating a new ticket in the portal.", ) - def _determine_stages(self): - """Get a dict with the stage per team that should be set as first to a created ticket - :returns a mapping of team identifier with the stage. - :rtype : dict (key=team_id, value=record of helpdesk.ticket.stage) - """ - result = dict.fromkeys(self.ids, self.env["helpdesk.ticket.stage"]) - for team in self: - result[team.id] = self.env["helpdesk.ticket.stage"].search( - ["|", ("team_ids", "=", False), ("team_ids", "in", team.id)], - order="sequence", - ) - return result + def _get_applicable_stages(self): + if self: + domain = [ + ("company_id", "in", [False, self.company_id.id]), + "|", + ("team_ids", "=", False), + ("team_ids", "=", self.id), + ] + else: + domain = [ + ("company_id", "in", [False, self.env.company.id]), + ("team_ids", "=", False), + ] + return self.env["helpdesk.ticket.stage"].search(domain) @api.depends("ticket_ids", "ticket_ids.stage_id") def _compute_todo_tickets(self): diff --git a/helpdesk_mgmt/static/description/index.html b/helpdesk_mgmt/static/description/index.html index b1ee4f4a6c..613f612b42 100644 --- a/helpdesk_mgmt/static/description/index.html +++ b/helpdesk_mgmt/static/description/index.html @@ -367,7 +367,7 @@

      Helpdesk Management

      !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:37cc770b0537354407fedcbe0d568ba9bdd6aa460144a7af475c60ae3f91ad27 +!! source digest: sha256:a417b3ef325ea73b03c6c64e0476702e5a35949224072491138ce827feb4d6e7 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

      Beta License: AGPL-3 OCA/helpdesk Translate me on Weblate Try me on Runboat

      This module adds Helpdesk functionality in Odoo.

      diff --git a/helpdesk_mgmt/tests/test_helpdesk_ticket.py b/helpdesk_mgmt/tests/test_helpdesk_ticket.py index bc5c3334f1..abc4ced815 100644 --- a/helpdesk_mgmt/tests/test_helpdesk_ticket.py +++ b/helpdesk_mgmt/tests/test_helpdesk_ticket.py @@ -121,19 +121,11 @@ def test_ticket_with_team_stage(self): new_ticket.team_id = False self.assertEqual(new_ticket.stage_id, self.new_stage) - def test_ticket_without_team_stage(self): - self.new_stage.team_ids = False - self.assertEqual( - self.ticket.stage_id, self.team_a._determine_stages()[self.team_a.id][0] - ) - self.assertEqual(self.ticket.stage_id, self.new_stage) - def test_ticket_without_team(self): new_ticket = self.env["helpdesk.ticket"].create( { "name": "New Ticket", "description": "Description", - "team_id": False, "user_id": self.user.id, "priority": "1", }