From 29fac1314d21905f05bcedca6aec477ede8398be Mon Sep 17 00:00:00 2001 From: eLBati Date: Wed, 8 Jul 2020 16:47:00 +0200 Subject: [PATCH 1/3] [IMP] helpdesk_mgmt: Use email layout to simplify all templates - Avoid email_cc (error "message without recipients") - Use coherent partner/user reference - Access button from e-mail notifications Semi-forward port of 98e5ef7f4a2e074283da3674654f662a28f02eed Please note that the commit a5041c25a79cd9620d30cc09dd9741f46aef7e76 (An e-mail is sent to the ticket after each create/edit) has not been forward ported because the assignment notify is done internally by odoo in `_message_auto_subscribe_followers` from `mail.thread` --- helpdesk_mgmt/README.rst | 4 + helpdesk_mgmt/data/helpdesk_data.xml | 216 +++----------------- helpdesk_mgmt/models/helpdesk_ticket.py | 56 ++++- helpdesk_mgmt/readme/CONTRIBUTORS.rst | 4 + helpdesk_mgmt/static/description/index.html | 4 + 5 files changed, 88 insertions(+), 196 deletions(-) diff --git a/helpdesk_mgmt/README.rst b/helpdesk_mgmt/README.rst index 2199878ffb..f82b257b4d 100644 --- a/helpdesk_mgmt/README.rst +++ b/helpdesk_mgmt/README.rst @@ -222,6 +222,10 @@ Contributors * Marcel Savegnago * Eduardo Aparício +* `TAKOBI `_: + + * Lorenzo Battistini + * `Obertix `_: * Vicent Cubells diff --git a/helpdesk_mgmt/data/helpdesk_data.xml b/helpdesk_mgmt/data/helpdesk_data.xml index fc2d671043..ce1ef7c9c7 100644 --- a/helpdesk_mgmt/data/helpdesk_data.xml +++ b/helpdesk_mgmt/data/helpdesk_data.xml @@ -32,105 +32,33 @@ {{object.company_id.partner_id.email}} {{not object.partner_id and object.partner_email or ''}}, The ticket {{object.number}} has been closed. {{object.partner_id.id}} {{object.partner_id.lang}} - - - - - - - - - - - - - - - -
- - - - -
- -
-
- - - - -
-

Hello ,

-

The ticket "" has been closed.

-
-
- - - - - - -
- - - - - -
-
+
+

Hello ,

+

The ticket "" has been closed.

+ + + + Thank you,

+
+
@@ -147,100 +75,14 @@ {{object.partner_id.lang}} - - - - - - - - - - - - - - - -
- - - - -
- -
-
- - - - -
-

Hello ,

-

The ticket "" stage has changed to .

-
-
- - - - - - -
- - - - - -
-
+
+

Hello ,

+

The ticket "" stage has changed to .

+
diff --git a/helpdesk_mgmt/models/helpdesk_ticket.py b/helpdesk_mgmt/models/helpdesk_ticket.py index c9885d542b..e67928ee71 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket.py +++ b/helpdesk_mgmt/models/helpdesk_ticket.py @@ -154,6 +154,15 @@ def _onchange_partner_id(self): def _creation_subtype(self): return self.env.ref("helpdesk_mgmt.hlp_tck_created") + def _message_auto_subscribe_followers(self, updated_values, default_subtype_ids): + """Auto-subscribe ticket partner.""" + result = super()._message_auto_subscribe_followers( + updated_values, default_subtype_ids + ) + if updated_values.get("partner_id"): + result.append((self.partner_id.id, default_subtype_ids, False)) + return result + @api.model_create_multi def create(self, vals_list): for vals in vals_list: @@ -209,12 +218,6 @@ def _prepare_ticket_number(self, values): seq = seq.with_company(values["company_id"]) return seq.next_by_code("helpdesk.ticket.sequence") or "/" - def _compute_access_url(self): - res = super()._compute_access_url() - for item in self: - item.access_url = "/my/ticket/%s" % (item.id) - return res - # --------------------------------------------------- # Mail gateway # --------------------------------------------------- @@ -251,10 +254,8 @@ def message_new(self, msg, custom_values=None): "partner_id": msg.get("author_id"), } defaults.update(custom_values) - # Write default values coming from msg ticket = super().message_new(msg, custom_values=defaults) - # Use mail gateway tools to search for partners to subscribe email_list = tools.email_split( (msg.get("to") or "") + "," + (msg.get("cc") or "") @@ -267,7 +268,6 @@ def message_new(self, msg, custom_values=None): if p ] ticket.message_subscribe(partner_ids) - return ticket def message_update(self, msg, update_vals=None): @@ -315,3 +315,41 @@ def _notify_get_reply_to(self, default=None): super(HelpdeskTicket, leftover)._notify_get_reply_to(default=default) ) return res + + # --------------------------------------------------- + # Portal + # --------------------------------------------------- + + def _compute_access_url(self): + res = super(HelpdeskTicket, self)._compute_access_url() + for ticket in self: + ticket.access_url = "/my/ticket/%s" % (ticket.id) + return res + + def _notify_get_recipients_groups(self, msg_vals=None): + groups = super(HelpdeskTicket, self)._notify_get_recipients_groups( + msg_vals=msg_vals + ) + self.ensure_one() + for group_name, _group_method, group_data in groups: + if group_name == "portal": + group_data["has_button_access"] = True + return groups + + def partner_can_access(self): + if not self.partner_id: + return False + user = ( + self.env["res.users"] + .sudo() + .search([("partner_id", "=", self.partner_id.id)]) + ) + if not user or not self.with_user(user).check_access_rights( + "read", raise_exception=False + ): + return False + return True + + def get_access_link(self): + # _notify_get_action_link is not callable from email template + return self._notify_get_action_link("view") diff --git a/helpdesk_mgmt/readme/CONTRIBUTORS.rst b/helpdesk_mgmt/readme/CONTRIBUTORS.rst index 6818625090..4731154219 100644 --- a/helpdesk_mgmt/readme/CONTRIBUTORS.rst +++ b/helpdesk_mgmt/readme/CONTRIBUTORS.rst @@ -35,6 +35,10 @@ * Marcel Savegnago * Eduardo Aparício +* `TAKOBI `_: + + * Lorenzo Battistini + * `Obertix `_: * Vicent Cubells diff --git a/helpdesk_mgmt/static/description/index.html b/helpdesk_mgmt/static/description/index.html index d8362816a1..c830361a63 100644 --- a/helpdesk_mgmt/static/description/index.html +++ b/helpdesk_mgmt/static/description/index.html @@ -577,6 +577,10 @@

Contributors

  • Eduardo Aparício
  • +
  • TAKOBI:
      +
    • Lorenzo Battistini
    • +
    +
  • Obertix:
    • Vicent Cubells
    From 977fd296b285cb714954768f2ddc0a36ad8500d0 Mon Sep 17 00:00:00 2001 From: PicchiSeba Date: Tue, 26 Nov 2024 12:25:11 +0100 Subject: [PATCH 2/3] [IMP]helpdesk_mgmt: simplify tests structure --- helpdesk_mgmt/tests/test_helpdesk_ticket.py | 56 +++++++++------------ 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/helpdesk_mgmt/tests/test_helpdesk_ticket.py b/helpdesk_mgmt/tests/test_helpdesk_ticket.py index 69aaf9c340..9088c117a3 100644 --- a/helpdesk_mgmt/tests/test_helpdesk_ticket.py +++ b/helpdesk_mgmt/tests/test_helpdesk_ticket.py @@ -7,10 +7,15 @@ class TestHelpdeskTicket(TestHelpdeskTicketBase): @classmethod def setUpClass(cls): super().setUpClass() + + cls.Partner = cls.env["res.partner"] + cls.Ticket = cls.env["helpdesk.ticket"] + cls.TicketTeam = cls.env["helpdesk.ticket.team"] + cls.ticket = cls.ticket_a_unassigned def test_helpdesk_ticket_team_company(self): - ticket_a = self.env["helpdesk.ticket"].create( + ticket_a = self.Ticket.create( { "name": "Test ticket A", "team_id": self.team_a.id, @@ -19,7 +24,7 @@ def test_helpdesk_ticket_team_company(self): ) self.assertEqual(ticket_a.company_id, self.company) self.team_b.company_id = False - ticket_b = self.env["helpdesk.ticket"].create( + ticket_b = self.Ticket.create( { "name": "Test ticket b", "team_id": self.team_b.id, @@ -30,32 +35,22 @@ def test_helpdesk_ticket_team_company(self): def test_helpdesk_ticket_team_company_extra(self): company = self.env["res.company"].create({"name": "Test company"}) - team = self.env["helpdesk.ticket.team"].create( - {"name": "Test team", "company_id": False} - ) - ticket = ( - self.env["helpdesk.ticket"] - .with_company(company) - .create( - { - "name": "Test ticket", - "team_id": team.id, - "description": "description", - } - ) + team = self.TicketTeam.create({"name": "Test team", "company_id": False}) + ticket = self.Ticket.with_company(company).create( + { + "name": "Test ticket", + "team_id": team.id, + "description": "description", + } ) self.assertEqual(ticket.company_id, company) team.company_id = self.company - ticket = ( - self.env["helpdesk.ticket"] - .with_company(company) - .create( - { - "name": "Test ticket", - "team_id": team.id, - "description": "description", - } - ) + ticket = self.Ticket.with_company(company).create( + { + "name": "Test ticket", + "team_id": team.id, + "description": "description", + } ) self.assertEqual(ticket.company_id, self.company) @@ -110,10 +105,7 @@ def test_helpdesk_ticket_copy(self): ) def test_helpdesk_ticket_message_new(self): - Partner = self.env["res.partner"] - Ticket = self.env["helpdesk.ticket"] - - newPartner = Partner.create( + newPartner = self.Partner.create( { "name": "Jill", "email": "jill@example.com", @@ -133,7 +125,7 @@ def test_helpdesk_ticket_message_new(self): "date": "2021-10-10", } try: - t = Ticket.message_new(msg_dict) + t = self.Ticket.message_new(msg_dict) except Exception as error: self.fail("%s: %s" % (type(error), error)) self.assertEqual(t.name, title, "The ticket should have the correct title.") @@ -154,7 +146,7 @@ def test_ticket_with_team_stage(self): "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( + new_ticket = self.Ticket.create( { "name": "New Ticket", "description": "Description", @@ -172,7 +164,7 @@ def test_ticket_with_team_stage(self): self.assertEqual(new_ticket.stage_id, self.new_stage) def test_ticket_without_team(self): - new_ticket = self.env["helpdesk.ticket"].create( + new_ticket = self.Ticket.create( { "name": "New Ticket", "description": "Description", From 60bfad794d2354d90790ec9ec06a773e1798fdb4 Mon Sep 17 00:00:00 2001 From: eLBati Date: Thu, 30 Jul 2020 12:11:00 +0200 Subject: [PATCH 3/3] [IMP] helpdesk_mgmt: Test access added Forward port of dfbc3698e76b3a1330f339ca78b49557b78c05ed --- helpdesk_mgmt/tests/common.py | 3 + helpdesk_mgmt/tests/test_helpdesk_ticket.py | 97 +++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/helpdesk_mgmt/tests/common.py b/helpdesk_mgmt/tests/common.py index a41e5f35f4..0eb9c9945e 100644 --- a/helpdesk_mgmt/tests/common.py +++ b/helpdesk_mgmt/tests/common.py @@ -33,6 +33,9 @@ def setUpClass(cls): groups="helpdesk_mgmt.group_helpdesk_user", context=ctx, ) + cls.admin = cls.env.ref("base.user_admin") + cls.user_portal = cls.env.ref("base.demo_user0") + cls.user_demo = cls.env.ref("base.user_demo") cls.stage_closed = cls.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_done") cls.team_a = helpdesk_ticket_team.create( {"name": "Team A", "user_ids": [(6, 0, [cls.user_own.id, cls.user.id])]} diff --git a/helpdesk_mgmt/tests/test_helpdesk_ticket.py b/helpdesk_mgmt/tests/test_helpdesk_ticket.py index 9088c117a3..52c674b868 100644 --- a/helpdesk_mgmt/tests/test_helpdesk_ticket.py +++ b/helpdesk_mgmt/tests/test_helpdesk_ticket.py @@ -1,5 +1,7 @@ import time +from odoo.tests import tagged + from .common import TestHelpdeskTicketBase @@ -173,3 +175,98 @@ def test_ticket_without_team(self): } ) self.assertEqual(self.new_stage, new_ticket.stage_id) + + def test_helpdesk_ticket_multiple(self): + partner_1 = self.Partner.create( + {"name": "Partner 1", "email": "partner1@test.com"} + ) + partner_2 = self.Partner.create( + {"name": "Partner 2", "email": "partner2@test.com"} + ) + tickets = self.Ticket.create( + [ + { + "name": "Test 1", + "description": "Ticket test number 1", + "user_id": self.user.id, + "partner_email": "partner@domain.com", + }, + { + "name": "Test 2", + "description": "Ticket test number 2", + "user_id": self.user.id, + "partner_id": partner_1.id, + }, + { + "name": "Test 3", + "description": "Ticket test number 3", + "user_id": self.user_demo.id, + "partner_id": partner_2.id, + }, + ] + ) + self.assertEqual(len(tickets), 3) + + def test_helpdesk_ticket_access(self): + t = self.Ticket.create( + { + "name": "Test 1", + "description": "Ticket test", + } + ) + self.assertEqual(t.access_url, "/my/ticket/%s" % t.id) + t.partner_id = self.user_portal.partner_id.id + self.assertTrue(t.partner_can_access()) + + def test_partner_can_access(self): + p = self.env.ref("base.res_partner_1") + t = self.Ticket.create( + { + "name": "Test 1", + "description": "Ticket test", + "partner_id": p.id, + } + ) + self.assertFalse(t.partner_can_access()) + t.partner_id = self.env.ref("base.user_admin").partner_id.id + self.assertTrue(t.partner_can_access()) + + def test_access_url(self): + t = self.Ticket.create( + { + "name": "Test 1", + "description": "Ticket test", + } + ) + t._compute_access_url() + self.assertEqual(t.access_url, "/my/ticket/%s" % t.id) + + +@tagged("post_install", "-at_install") +class TestHelpdeskTicketPostInstall(TestHelpdeskTicketBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.Ticket = cls.env["helpdesk.ticket"] + cls.Message = cls.env["mail.message"] + + def test_helpdesk_ticket_assign_notify(self): + t = self.Ticket.create( + { + "name": "Test 1", + "description": "Ticket test", + } + ) + t.user_id = self.user_demo.id + m = self.Message.search( + [ + ("model", "=", "helpdesk.ticket"), + ("res_id", "=", t.id), + ("message_type", "=", "user_notification"), + ] + ) + self.assertTrue( + "You have been assigned to the Helpdesk Ticket %s" % t.display_name + in m.body + )