From d6146d732f73f0c0b85a4410d14470c63d861dee 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/__manifest__.py | 1 + helpdesk_mgmt/controllers/main.py | 1 + helpdesk_mgmt/data/helpdesk_data.xml | 235 ++++---------------- helpdesk_mgmt/data/ir_config_parameter.xml | 9 + helpdesk_mgmt/models/helpdesk_ticket.py | 86 ++++++- helpdesk_mgmt/readme/CONTRIBUTORS.rst | 4 + helpdesk_mgmt/static/description/index.html | 4 + 8 files changed, 146 insertions(+), 198 deletions(-) create mode 100644 helpdesk_mgmt/data/ir_config_parameter.xml diff --git a/helpdesk_mgmt/README.rst b/helpdesk_mgmt/README.rst index dfd330fb07..2d1caa2e36 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/__manifest__.py b/helpdesk_mgmt/__manifest__.py index 156a332f9d..e34ae6277a 100644 --- a/helpdesk_mgmt/__manifest__.py +++ b/helpdesk_mgmt/__manifest__.py @@ -19,6 +19,7 @@ "depends": ["mail", "portal"], "data": [ "data/helpdesk_data.xml", + "data/ir_config_parameter.xml", "security/helpdesk_security.xml", "security/ir.model.access.csv", "views/res_partner_views.xml", diff --git a/helpdesk_mgmt/controllers/main.py b/helpdesk_mgmt/controllers/main.py index ab772c6883..6bc4d2095f 100644 --- a/helpdesk_mgmt/controllers/main.py +++ b/helpdesk_mgmt/controllers/main.py @@ -82,6 +82,7 @@ def _prepare_submit_ticket_vals(self, **kw): "channel_id": request.env.ref( "helpdesk_mgmt.helpdesk_ticket_channel_web", False ).id, + "stage_id": request.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_new").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, diff --git a/helpdesk_mgmt/data/helpdesk_data.xml b/helpdesk_mgmt/data/helpdesk_data.xml index fc2d671043..043688f2e5 100644 --- a/helpdesk_mgmt/data/helpdesk_data.xml +++ b/helpdesk_mgmt/data/helpdesk_data.xml @@ -32,105 +32,53 @@ {{object.company_id.partner_id.email}} {{not object.partner_id and object.partner_email or ''}}, + name="email_to" + >${not object.partner_id and object.partner_email or ''|safe}, The ticket {{object.number}} has been closed. {{object.partner_id.id}} {{object.partner_id.lang}} - - - - - - - - - - - - - - - -
- - - - -
- -
-
- - - - -
-

Hello ,

-

The ticket "" has been closed.

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

Hello ${object.partner_id.name or object.partner_name or ''},

+

The ticket "${object.display_name or 'n/a'}" has been closed.

+ % if object.partner_can_access(): + + % endif + Thank you,

+ ${user.signature | safe}
+
+
+ + + Helpdesk Created Ticket Notification Email + + ${object.company_id.partner_id.email} + ${('' if object.partner_id.email and object.partner_id.email == object.partner_email else object.partner_email) | safe}, + The ticket ${object.number} has been created. + ${object.partner_id.id if object.partner_id.email and object.partner_id.email == object.partner_email else False} + + ${object.partner_id.lang} + +
+

Hello ${object.partner_id.name or object.partner_name or ''},

+

The ticket "${object.display_name or 'n/a'}" has been created.

+

You can reply to this email to add information to the ticket.

+
+ ]]>
@@ -147,100 +95,11 @@ {{object.partner_id.lang}} - - - - - - - - - - - - - - - -
- - - - -
- -
-
- - - - -
-

Hello ,

-

The ticket "" stage has changed to .

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

Hello ${object.partner_id.name or object.partner_name or ''},

+

The ticket "${object.display_name}" stage has changed to ${object.stage_id.name}.

+
diff --git a/helpdesk_mgmt/data/ir_config_parameter.xml b/helpdesk_mgmt/data/ir_config_parameter.xml new file mode 100644 index 0000000000..65ef00af77 --- /dev/null +++ b/helpdesk_mgmt/data/ir_config_parameter.xml @@ -0,0 +1,9 @@ + + + + + helpdesk_mgmt.created_ticket_template_name + helpdesk_mgmt.created_ticket_template + + + diff --git a/helpdesk_mgmt/models/helpdesk_ticket.py b/helpdesk_mgmt/models/helpdesk_ticket.py index 57ee374290..fd6e2d9b99 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket.py +++ b/helpdesk_mgmt/models/helpdesk_ticket.py @@ -132,6 +132,28 @@ def _read_group_stage_ids(self, stages, domain, order): ) active = fields.Boolean(default=True) + def _send_mail_to_partner(self, template_name): + """Send a feedback message to the contact linked to this newly created ticket + (whatever it is a real partner or just its e-mail). + Note: The purpose of this function is to replace the stage's `mail_template_id` + role (that just doesn't work when the ticket is created from the portal or when + `partner_id` is set)""" + created_ticket_template = self.env.ref(template_name, raise_if_not_found=False) + if created_ticket_template: + created_ticket_template.send_mail( + self.id, + force_send=True, + email_layout_xmlid="mail.mail_notification_light", + ) + + @api.model + def _get_created_ticket_template_name(self): + return ( + self.env["ir.config_parameter"] + .sudo() + .get_param("helpdesk_mgmt.created_ticket_template_name") + ) + def name_get(self): res = [] for rec in self: @@ -154,6 +176,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: @@ -165,7 +196,13 @@ def create(self, vals_list): team = self.env["helpdesk.ticket.team"].browse([vals["team_id"]]) if team.company_id: vals["company_id"] = team.company_id.id - return super().create(vals_list) + res = super().create(vals_list) + created_ticket_template_name = self._get_created_ticket_template_name() + if created_ticket_template_name: + for rec in res: + if rec.partner_id or rec.partner_email: + rec._send_mail_to_partner(created_ticket_template_name) + return res def copy(self, default=None): self.ensure_one() @@ -198,12 +235,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 # --------------------------------------------------- @@ -240,10 +271,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 "") @@ -256,7 +285,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): @@ -304,3 +332,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 768a4243b5..34c458ee86 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 761d5b0a0b54b5a25628dfe520366513ee8ed9e1 Mon Sep 17 00:00:00 2001 From: eLBati Date: Thu, 30 Jul 2020 12:11:00 +0200 Subject: [PATCH 2/3] [IMP] helpdesk_mgmt: Test access added Forward port of dfbc3698e76b3a1330f339ca78b49557b78c05ed --- helpdesk_mgmt/tests/common.py | 3 + helpdesk_mgmt/tests/test_helpdesk_ticket.py | 100 ++++++++++++++++++++ 2 files changed, 103 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 69aaf9c340..6d40132642 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 @@ -181,3 +183,101 @@ def test_ticket_without_team(self): } ) self.assertEqual(self.new_stage, new_ticket.stage_id) + + def test_helpdesk_ticket_multiple(self): + Ticket = self.env["helpdesk.ticket"] + Partner = self.env["res.partner"] + + partner_1 = Partner.create({"name": "Partner 1", "email": "partner1@test.com"}) + partner_2 = Partner.create({"name": "Partner 2", "email": "partner2@test.com"}) + tickets = 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): + Ticket = self.env["helpdesk.ticket"] + t = 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): + Ticket = self.env["helpdesk.ticket"] + self.assertFalse(Ticket.partner_can_access()) + p = self.env.ref("base.res_partner_1") + t = 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): + Ticket = self.env["helpdesk.ticket"] + t = 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() + + def test_helpdesk_ticket_assign_notify(self): + Ticket = self.env["helpdesk.ticket"] + Message = self.env["mail.message"] + + t = Ticket.create( + { + "name": "Test 1", + "description": "Ticket test", + } + ) + t.user_id = self.user_demo.id + m = 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 + ) From 8a1fc5e72a8ffae0aa8878480bda841f527f5a60 Mon Sep 17 00:00:00 2001 From: Yann Papouin Date: Tue, 16 May 2023 10:09:03 +0200 Subject: [PATCH 3/3] [IMP] helpdesk_mgmt: Doc update --- helpdesk_mgmt/README.rst | 2 +- helpdesk_mgmt/readme/CONFIGURE.rst | 2 +- .../static/description/{Stage.PNG => Stages.PNG} | Bin helpdesk_mgmt/static/description/index.html | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename helpdesk_mgmt/static/description/{Stage.PNG => Stages.PNG} (100%) diff --git a/helpdesk_mgmt/README.rst b/helpdesk_mgmt/README.rst index 2d1caa2e36..f175125094 100644 --- a/helpdesk_mgmt/README.rst +++ b/helpdesk_mgmt/README.rst @@ -77,7 +77,7 @@ Stages #. Edit or create a new stage. #. Set the name for the stage. #. Set the sequence order for the stage. -#. You can select an Email template. +#. You can select an email template that will be automatically sent when a ticket reaches this stage. #. Mark the Unattended checkbox if the stage contains unattended tickets. #. Mark the Closed checkbox if the stage contains closed tickets. #. You can add a description for the stage. diff --git a/helpdesk_mgmt/readme/CONFIGURE.rst b/helpdesk_mgmt/readme/CONFIGURE.rst index a99b90ab25..712eb9b2af 100644 --- a/helpdesk_mgmt/readme/CONFIGURE.rst +++ b/helpdesk_mgmt/readme/CONFIGURE.rst @@ -37,7 +37,7 @@ Stages #. Edit or create a new stage. #. Set the name for the stage. #. Set the sequence order for the stage. -#. You can select an Email template. +#. You can select an email template that will be automatically sent when a ticket reaches this stage. #. Mark the Unattended checkbox if the stage contains unattended tickets. #. Mark the Closed checkbox if the stage contains closed tickets. #. You can add a description for the stage. diff --git a/helpdesk_mgmt/static/description/Stage.PNG b/helpdesk_mgmt/static/description/Stages.PNG similarity index 100% rename from helpdesk_mgmt/static/description/Stage.PNG rename to helpdesk_mgmt/static/description/Stages.PNG diff --git a/helpdesk_mgmt/static/description/index.html b/helpdesk_mgmt/static/description/index.html index 34c458ee86..8b7615e15d 100644 --- a/helpdesk_mgmt/static/description/index.html +++ b/helpdesk_mgmt/static/description/index.html @@ -435,7 +435,7 @@

    Stages

  • Edit or create a new stage.
  • Set the name for the stage.
  • Set the sequence order for the stage.
  • -
  • You can select an Email template.
  • +
  • You can select an email template that will be automatically sent when a ticket reaches this stage.
  • Mark the Unattended checkbox if the stage contains unattended tickets.
  • Mark the Closed checkbox if the stage contains closed tickets.
  • You can add a description for the stage.