diff --git a/helpdesk_mgmt/data/helpdesk_data.xml b/helpdesk_mgmt/data/helpdesk_data.xml index 41a5c8597f..ab8fc94fa8 100644 --- a/helpdesk_mgmt/data/helpdesk_data.xml +++ b/helpdesk_mgmt/data/helpdesk_data.xml @@ -10,17 +10,83 @@ - Ticket Assignment + Helpdesk Ticket Assignment ${object.company_id.partner_id.email} - ${not object.partner_id and object.partner_email or ''|safe}, ${object.company_id.name} Ticket Assignment (Ref ${object.number or 'n/a' }) - ${object.partner_id.id} + ${object.user_id.partner_id.id} - ${object.partner_id.lang} - -

Hello ${object.user_id.name},

-

The ticket ${object.number} has been assigned to you.

+ ${object.user_id.lang} + + +
+ + + + + + + + + + + + + + + +
+ + + +
+ Ticket
+ + ${object.number or 'n/a'} + +
+ ${object.company_id.name} +
+
+
+
+ + + +
+
+

Hello ${object.user_id.name},

+

The ticket ${object.number or 'n/a'} has been assigned to you.

+ + Thank you,

+ ${user.signature | safe}
+
+
+
+
+
+ + + +
+ ${object.company_id.name} +
+ ${object.company_id.phone} + % if object.company_id.email + | ${object.company_id.email} + % endif + % if object.company_id.website + | + ${object.company_id.website} + + % endif +
+
+
@@ -28,128 +94,168 @@ Helpdesk Closed Ticket Notification Email ${object.company_id.partner_id.email} - ${not object.partner_id and object.partner_email or ''|safe}, + ${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} - - - - - - - - - - - - - - - - - - -
- - - - -
- ${object.company_id.name} -
-
- - - - -
-

Hello ${object.user_id.name},

-

The ticket ${object.number} has been closed.

-
-
- - - - - - -
- ${object.company_id.phone} - - ${object.company_id.email} - - ${object.company_id.website} -
-
- - - ]]>
+ + +
+ + + + + + + + + + + + + + + +
+ + + +
+ Ticket
+ + ${object.number or 'n/a'} + +
+ ${object.company_id.name} +
+
+
+
+ + + +
+
+

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

+

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

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

+ ${user.signature | safe}
+
+
+
+
+
+ + + +
+ ${object.company_id.name} +
+ ${object.company_id.phone} + % if object.company_id.email + | ${object.company_id.email} + % endif + % if object.company_id.website + | + ${object.company_id.website} + + % endif +
+
+
+
- - Helpdesk Changed Stage notification Email + + Helpdesk Created Ticket Notification Email ${object.company_id.partner_id.email} - ${not object.partner_id and object.partner_email or ''|safe}, - The ticket ${object.number} stage has changed. + ${not object.partner_id and object.partner_email or ''|safe} + The ticket ${object.number} has been created. ${object.partner_id.id} ${object.partner_id.lang} - - - - - - - - - - - - - - - - - - -
- - - - -
- -
-
- - - - -
-

Hello ${object.user_id.name},

-

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

-
-
- - - - - - -
- ${object.company_id.phone} - - ${object.company_id.email} - - ${object.company_id.website} -
-
- - - ]]> + + +
+ + + + + + + + + + + + + + + +
+ + + +
+ Ticket
+ + ${object.number or 'n/a'} + +
+ ${object.company_id.name} +
+
+
+
+ + + +
+
+

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

+

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

+

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

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

+ ${user.signature | safe}
+
+
+
+
+
+ + + +
+ ${object.company_id.name} +
+ ${object.company_id.phone} + % if object.company_id.email + | ${object.company_id.email} + % endif + % if object.company_id.website + | + ${object.company_id.website} + + % endif +
+
+
diff --git a/helpdesk_mgmt/models/helpdesk_ticket.py b/helpdesk_mgmt/models/helpdesk_ticket.py index 707815c5cf..0b8fa2b125 100644 --- a/helpdesk_mgmt/models/helpdesk_ticket.py +++ b/helpdesk_mgmt/models/helpdesk_ticket.py @@ -1,4 +1,5 @@ from odoo import _, api, fields, models, tools +from email.utils import getaddresses class HelpdeskTicket(models.Model): @@ -7,7 +8,7 @@ class HelpdeskTicket(models.Model): _description = 'Helpdesk Ticket' _rec_name = 'number' _order = 'number desc' - _inherit = ['mail.thread', 'mail.activity.mixin'] + _inherit = ['mail.thread', 'mail.activity.mixin', 'portal.mixin'] def _get_default_stage_id(self): return self.env['helpdesk.ticket.stage'].search([], limit=1).id @@ -80,11 +81,45 @@ def _read_group_stage_ids(self, stages, domain, order): def send_user_mail(self): self.env.ref('helpdesk_mgmt.assignment_email_template'). \ - send_mail(self.id) + send_mail(self.id, force_send=True) + + def send_partner_mail(self): + self.env.ref('helpdesk_mgmt.created_ticket_template'). \ + send_mail(self.id, force_send=True) def assign_to_me(self): self.write({'user_id': self.env.user.id}) + def _compute_access_url(self): + super(HelpdeskTicket, self)._compute_access_url() + for ticket in self: + ticket.access_url = '/my/ticket/%s' % (ticket.id) + + 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: + return False + if not self.sudo(user.id).check_access_rights('read', raise_exception=False): + return False + else: + return True + + def get_access_link(self): + # _notify_get_action_link is not callable from email template + return self._notify_get_action_link('view') + + @api.multi + def _notify_get_groups(self, message, groups): + groups = super(HelpdeskTicket, self)._notify_get_groups(message, groups) + self.ensure_one() + for group_name, group_method, group_data in groups: + if group_name == 'portal': + group_data['has_button_access'] = True + return groups + @api.onchange('partner_id') def _onchange_partner_id(self): if self.partner_id: @@ -133,6 +168,11 @@ def create(self, vals): # Check if mail to the user has to be sent if vals.get('user_id') and res: res.send_user_mail() + res.message_subscribe(partner_ids=res.user_id.partner_id.ids) + if (vals.get('partner_id') or vals.get('partner_email')) and res: + res.send_partner_mail() + if res.partner_id: + res.message_subscribe(partner_ids=res.partner_id.ids) return res @api.multi @@ -164,6 +204,7 @@ def write(self, vals): for ticket in self: if vals.get('user_id'): ticket.send_user_mail() + ticket.message_subscribe(partner_ids=ticket.user_id.partner_id.ids) return res def _prepare_ticket_number(self, values): @@ -197,9 +238,12 @@ def message_new(self, msg, custom_values=None): defaults = { 'name': msg.get('subject') or _("No Subject"), 'description': msg.get('body'), - 'partner_email': msg.get('from'), 'partner_id': msg.get('author_id') } + res = getaddresses([msg.get('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 diff --git a/helpdesk_mgmt/readme/CONTRIBUTORS.rst b/helpdesk_mgmt/readme/CONTRIBUTORS.rst index 9156b68f52..f805d04373 100644 --- a/helpdesk_mgmt/readme/CONTRIBUTORS.rst +++ b/helpdesk_mgmt/readme/CONTRIBUTORS.rst @@ -31,3 +31,7 @@ * Marcel Savegnago * Eduardo Aparício + +* `TAKOBI `_: + + * Lorenzo Battistini