diff --git a/helpdesk_mgmt/README.rst b/helpdesk_mgmt/README.rst index 3e6926d1e9..298684e031 100644 --- a/helpdesk_mgmt/README.rst +++ b/helpdesk_mgmt/README.rst @@ -1,7 +1,3 @@ -.. image:: https://odoo-community.org/readme-banner-image - :target: https://odoo-community.org/get-involved?utm_source=readme - :alt: Odoo Community Association - =================== Helpdesk Management =================== @@ -17,7 +13,7 @@ Helpdesk Management .. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png :target: https://odoo-community.org/page/development-status :alt: Production/Stable -.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhelpdesk-lightgray.png?logo=github @@ -129,6 +125,16 @@ permissions set in Helpdesk. not assigned to any team nor user. 3. *User*: User is able to see all the tickets. +Customer notifications +---------------------- + +If you want portal users to receive an email when a ticket is created: + +1. Enable debug mode +2. Open the "Ticket Created" subtype in Settings > Technical > Discuss > + Subtypes +3. Enable the ``Default`` flag + .. |image1| image:: https://raw.githubusercontent.com/OCA/helpdesk/18.0/helpdesk_mgmt/static/description/Channels.PNG .. |image2| image:: https://raw.githubusercontent.com/OCA/helpdesk/18.0/helpdesk_mgmt/static/description/Categories.PNG .. |image3| image:: https://raw.githubusercontent.com/OCA/helpdesk/18.0/helpdesk_mgmt/static/description/Stages.PNG diff --git a/helpdesk_mgmt/controllers/main.py b/helpdesk_mgmt/controllers/main.py index 0a01b46f68..f7711a6d80 100644 --- a/helpdesk_mgmt/controllers/main.py +++ b/helpdesk_mgmt/controllers/main.py @@ -102,15 +102,17 @@ def _prepare_submit_ticket_vals(self, **kw): ) ) 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) def submit_ticket(self, **kw): vals = self._prepare_submit_ticket_vals(**kw) - new_ticket = request.env["helpdesk.ticket"].sudo().create(vals) + new_ticket = ( + request.env["helpdesk.ticket"] + .sudo() + .with_context(mail_notify_author=True) + .create(vals) + ) new_ticket.message_subscribe(partner_ids=request.env.user.partner_id.ids) if kw.get("attachment"): for c_file in request.httprequest.files.getlist("attachment"): diff --git a/helpdesk_mgmt/models/helpdesk_ticket.py b/helpdesk_mgmt/models/helpdesk_ticket.py index 4c6f85a904..9b6c1abbee 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket.py +++ b/helpdesk_mgmt/models/helpdesk_ticket.py @@ -315,8 +315,6 @@ def _track_template(self, tracking): res["stage_id"] = ( ticket.stage_id.mail_template_id, { - # Need to set mass_mail so that the email will always be sent - "composition_mode": "mass_mail", "auto_delete_keep_log": False, "subtype_id": self.env["ir.model.data"]._xmlid_to_res_id( "mail.mt_note" diff --git a/helpdesk_mgmt/readme/CONFIGURE.md b/helpdesk_mgmt/readme/CONFIGURE.md index 5a1b50415c..98742443b7 100644 --- a/helpdesk_mgmt/readme/CONFIGURE.md +++ b/helpdesk_mgmt/readme/CONFIGURE.md @@ -79,3 +79,11 @@ permissions set in Helpdesk. assigned to the teams to which he/she belongs or the tickets that are not assigned to any team nor user. 3. *User*: User is able to see all the tickets. + +## Customer notifications + +If you want portal users to receive an email when a ticket is created: + +1. Enable debug mode +2. Open the "Ticket Created" subtype in Settings > Technical > Discuss > Subtypes +3. Enable the `Default` flag diff --git a/helpdesk_mgmt/static/description/index.html b/helpdesk_mgmt/static/description/index.html index ee8b8b9254..8940479d6c 100644 --- a/helpdesk_mgmt/static/description/index.html +++ b/helpdesk_mgmt/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +Helpdesk Management -
+
+

Helpdesk Management

- - -Odoo Community Association - -
-

Helpdesk Management

-

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

+

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

This module adds Helpdesk functionality in Odoo.

Table of contents

-

Configuration

+

Configuration

To configure this module, you need to:

  1. Edit or create new channels.
  2. @@ -410,7 +406,7 @@

    Configuration

  3. Edit or create new tags.
-

Channels

+

Channels

  1. Go to Helpdesk > Configuration > Channels to edit or create new channels.
  2. @@ -421,7 +417,7 @@

    Channels

    image1

-

Categories

+

Categories

  1. Go to Helpdesk > Configuration > Categories to edit or create new categories.
  2. @@ -432,7 +428,7 @@

    Categories

    image2

-

Stages

+

Stages

  1. Go to Helpdesk > Configuration > Stages to edit or create new stages.
  2. @@ -451,7 +447,7 @@

    Stages

    in the list view.

-

Teams

+

Teams

  1. Go to Helpdesk > Configuration > Teams to edit or create new teams.
  2. Edit or create a new team.
  3. @@ -462,7 +458,7 @@

    Teams

    image4

-

Tags

+

Tags

  1. Go to Helpdesk > Configuration > Ticket Tags to edit or create new tags.
  2. @@ -474,7 +470,7 @@

    Tags

    image5

-

Permissions

+

Permissions

There are restrictions to read tickets according to the user’s permissions set in Helpdesk.

    @@ -487,9 +483,19 @@

    Permissions

  1. User: User is able to see all the tickets.
+
+

Customer notifications

+

If you want portal users to receive an email when a ticket is created:

+
    +
  1. Enable debug mode
  2. +
  3. Open the “Ticket Created” subtype in Settings > Technical > Discuss > +Subtypes
  4. +
  5. Enable the Default flag
  6. +
+
-

Usage

+

Usage

  1. Go to Helpdesk or Helpdesk > Dashboard to see the tickets dashboard
  2. @@ -513,7 +519,7 @@

    Usage

    Tickets01 Tickets02

-

Known issues / Roadmap

+

Known issues / Roadmap

  • Add a tour feature similar to what the project module defines to discover projects / tasks.
  • @@ -523,7 +529,7 @@

    Known issues / Roadmap

-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -531,9 +537,9 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • AdaptiveCity
  • Tecnativa
  • @@ -545,7 +551,7 @@

    Authors

-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -618,6 +624,5 @@

Maintainers

-
diff --git a/helpdesk_mgmt/tests/test_helpdesk_portal.py b/helpdesk_mgmt/tests/test_helpdesk_portal.py index c87a91353d..f84b2789c0 100644 --- a/helpdesk_mgmt/tests/test_helpdesk_portal.py +++ b/helpdesk_mgmt/tests/test_helpdesk_portal.py @@ -1,8 +1,11 @@ # Copyright 2023 Tecnativa - Víctor Martínez # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html # import odoo.tests +from lxml import etree + from odoo import http -from odoo.tests.common import new_test_user, tagged +from odoo.tests.common import RecordCapturer, new_test_user, tagged +from odoo.tools import html2plaintext from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT, HttpCaseWithUserPortal @@ -204,3 +207,76 @@ def _call_close_ticket(self, ticket, stage): self.assertTrue(resp.is_redirect) # http://127.0.0.1:8069/my/ticket/ self.assertTrue(resp.headers["Location"].endswith(f"/my/ticket/{ticket.id}")) return resp + + def _assert_html_shows_ticket_link(self, html_content, ticket): + content_html = etree.fromstring(html_content, parser=etree.HTMLParser()) + for link in content_html.xpath("//a"): + if ticket.access_token in link.get("href"): + ticket_link = link + break + else: + self.fail("Link for ticket not found") + + # In some cases (no `record_name`) the link is there + # but it contains no visible text, so it is not shown in the email. + for text in ticket_link.itertext(): + if html2plaintext(text): + # Could be "View Ticket", or similar + break + else: + self.fail("Link for ticket not shown") + + def test_stage_changed_mail_link(self): + """The stage changed email includes an access link to open the Ticket.""" + # Arrange + template = self.env.ref("helpdesk_mgmt.changed_stage_template") + stage = self.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_in_progress") + stage.mail_template_id = template + portal_user = self.user_portal + self.authenticate(portal_user.login, portal_user.login) + with ( + RecordCapturer(self.env["helpdesk.ticket"], []) as ticket_catcher, + ): + self._submit_ticket() + ticket = ticket_catcher.records + + # Act + with RecordCapturer(self.env["mail.mail"], []) as emails_catcher: + ticket.with_context( + mail_notrack=False, + tracking_disable=False, + ).stage_id = stage + # Emails are sent in a precommit hook, + # that in tests is usually not executed + self.env.cr.precommit.run() + + # Assert + stage_changed_email = emails_catcher.records + self._assert_html_shows_ticket_link(stage_changed_email.body_html, ticket) + + def test_create_notification(self): + """ + If the Ticket Creation subtype is Default, + the portal user receives an email on Ticket creation. + """ + # Arrange + creation_subtype = self.env.ref("helpdesk_mgmt.hlp_tck_created") + creation_subtype.default = True + portal_user = self.user_portal + self.authenticate(portal_user.login, portal_user.login) + + # Act + with ( + RecordCapturer(self.env["mail.mail"], []) as email_catcher, + RecordCapturer(self.env["helpdesk.ticket"], []) as ticket_catcher, + ): + self._submit_ticket() + + # Assert: The email is for the user that created the ticket + # and shows a link with access token that points to the ticket + ticket = ticket_catcher.records + creation_email = email_catcher.records.filtered( + lambda email, subtype=creation_subtype: email.subtype_id == subtype + ) + self.assertIn(portal_user.partner_id, creation_email.recipient_ids) + self._assert_html_shows_ticket_link(creation_email.body_html, ticket)