diff --git a/helpdesk_mgmt/README.rst b/helpdesk_mgmt/README.rst index b2cdd21515..2474ce2947 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:357a54501fd1c1b608a3bf56d0ecaf11c1e7e0891f1e615a94e9298cec37580b + !! source digest: sha256:9512cd33b07790d26d4669f420a5a7191d15dc3fe83683b82307c952449e1dee !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -211,6 +211,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 657005f3c3..2dde5723e8 100644 --- a/helpdesk_mgmt/__manifest__.py +++ b/helpdesk_mgmt/__manifest__.py @@ -17,6 +17,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 0fe3799d4f..f043bf930d 100644 --- a/helpdesk_mgmt/controllers/main.py +++ b/helpdesk_mgmt/controllers/main.py @@ -66,6 +66,7 @@ def _prepare_submit_ticket_vals(self, **kw): "description": plaintext2html(kw.get("description")), "name": kw.get("subject"), "attachment_ids": False, + "stage_id": request.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_new").id, "channel_id": request.env["helpdesk.ticket.channel"] .sudo() .search([("name", "=", "Web")]) diff --git a/helpdesk_mgmt/data/helpdesk_data.xml b/helpdesk_mgmt/data/helpdesk_data.xml index 5e43f8eea7..5fc5aad88d 100644 --- a/helpdesk_mgmt/data/helpdesk_data.xml +++ b/helpdesk_mgmt/data/helpdesk_data.xml @@ -14,7 +14,7 @@ ${object.company_id.partner_id.email} ${not object.partner_id and object.partner_email or ''|safe}, The ticket ${object.number} has been closed. ${object.partner_id.id} @@ -22,60 +22,46 @@ ${object.partner_id.lang} - - - - - - - - - - - - - - - - - -
- - - - -
- ${object.company_id.name} -
-
- - - - -
-

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

-

The ticket "${object.display_name}" has been closed.

-
-
- - - - - - -
- ${object.company_id.phone} - - ${object.company_id.email} - - ${object.company_id.website} -
-
- - + > +

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(): +
+ + View Ticket + +
+ % 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.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.

+
+ ]]> +
+
Helpdesk Changed Stage notification Email @@ -90,57 +76,10 @@ - - - - - - - - - - - - - - - - - -
- - - - -
- -
-
- - - - -
-

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

-

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

-
-
- - - - - - -
- ${object.company_id.phone} - - ${object.company_id.email} - - ${object.company_id.website} -
-
- - +
+

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..184737a7a1 --- /dev/null +++ b/helpdesk_mgmt/data/ir_config_parameter.xml @@ -0,0 +1,9 @@ + + + + + helpdesk_mgmt.created_ticket_template_name + created_ticket_template + + + diff --git a/helpdesk_mgmt/models/helpdesk_ticket.py b/helpdesk_mgmt/models/helpdesk_ticket.py index 6b7caa8439..0b9f1d2cb8 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket.py +++ b/helpdesk_mgmt/models/helpdesk_ticket.py @@ -1,3 +1,5 @@ +from email.utils import getaddresses + from odoo import _, api, fields, models, tools from odoo.exceptions import AccessError @@ -111,6 +113,26 @@ 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, notif_layout="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: @@ -140,6 +162,15 @@ def _get_default_email_channel(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: @@ -157,7 +188,14 @@ def create(self, vals_list): channel_email_id = self._get_default_email_channel() if channel_email_id: vals["channel_id"] = channel_email_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() @@ -190,11 +228,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): - super()._compute_access_url() - for item in self: - item.access_url = "/my/ticket/%s" % (item.id) - def _prepare_team_id(self, values): category = self.env["helpdesk.ticket.category"].browse(values["category_id"]) if category.default_team_id: @@ -236,13 +269,20 @@ def message_new(self, msg, custom_values=None): "partner_email": partner_email, "partner_id": msg.get("author_id"), } + if not msg.get("author_id"): defaults["partner_name"] = partner_name - defaults.update(custom_values) + msg_from = msg.get("from", "") + if msg_from: + res = getaddresses([msg_from]) + if res: + defaults["partner_name"] = res[0][0] + defaults["partner_email"] = res[0][1] + + 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 "") @@ -255,7 +295,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): @@ -337,3 +376,38 @@ def action_do_send_email(self): "target": "new", "context": ctx, } + + # --------------------------------------------------- + # Portal + # --------------------------------------------------- + + def _compute_access_url(self): + super(HelpdeskTicket, self)._compute_access_url() + for ticket in self: + ticket.access_url = "/my/ticket/%s" % (ticket.id) + + def _notify_get_groups(self, msg_vals=None): + groups = super(HelpdeskTicket, self)._notify_get_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 129e42eba4..a502a7972a 100644 --- a/helpdesk_mgmt/readme/CONTRIBUTORS.rst +++ b/helpdesk_mgmt/readme/CONTRIBUTORS.rst @@ -33,6 +33,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 1040b04ce8..7197a590e1 100644 --- a/helpdesk_mgmt/static/description/index.html +++ b/helpdesk_mgmt/static/description/index.html @@ -1,3 +1,4 @@ + @@ -366,7 +367,7 @@

Helpdesk Management

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:357a54501fd1c1b608a3bf56d0ecaf11c1e7e0891f1e615a94e9298cec37580b +!! source digest: sha256:9512cd33b07790d26d4669f420a5a7191d15dc3fe83683b82307c952449e1dee !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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

This module adds Helpdesk functionality in Odoo.

@@ -563,6 +564,10 @@

Contributors

  • Eduardo Aparício
  • +
  • TAKOBI:
      +
    • Lorenzo Battistini
    • +
    +
  • Obertix:
    • Vicent Cubells