diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index 3d50eb10d75e3f0a9e66d761a4b00361c7bd66e3..1bb62b0c50b628f96a9781382c6512132db0db89 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -1197,7 +1197,7 @@ class Lead(models.Model): update_vals[key] = res.group(2).lower() return super(Lead, self).message_update(msg_dict, update_vals=update_vals) - def _message_post_after_hook(self, message, values): + def _message_post_after_hook(self, message, values, notif_layout): if self.email_from and not self.partner_id: # we consider that posting a message with a specified recipient (not a follower, a specific one) # on a document without customer means that it was created through the chatter using @@ -1208,7 +1208,7 @@ class Lead(models.Model): ('partner_id', '=', False), ('email_from', '=', new_partner.email), ('stage_id.fold', '=', False)]).write({'partner_id': new_partner.id}) - return super(Lead, self)._message_post_after_hook(message, values) + return super(Lead, self)._message_post_after_hook(message, values, notif_layout) @api.multi def message_partner_info_from_emails(self, emails, link_mail=False): diff --git a/addons/event/models/event.py b/addons/event/models/event.py index 70a71080650a6fe79ca52dac532dee5ac8b26120..8551c6ec3891be8cbe2f590cb26bf89d5f85bc1a 100644 --- a/addons/event/models/event.py +++ b/addons/event/models/event.py @@ -448,7 +448,7 @@ class EventRegistration(models.Model): pass return recipients - def _message_post_after_hook(self, message, values): + def _message_post_after_hook(self, message, values, notif_layout): if self.email and not self.partner_id: # we consider that posting a message with a specified recipient (not a follower, a specific one) # on a document without customer means that it was created through the chatter using @@ -460,7 +460,7 @@ class EventRegistration(models.Model): ('email', '=', new_partner.email), ('state', 'not in', ['cancel']), ]).write({'partner_id': new_partner.id}) - return super(EventRegistration, self)._message_post_after_hook(message, values) + return super(EventRegistration, self)._message_post_after_hook(message, values, notif_layout) @api.multi def action_send_badge_email(self): diff --git a/addons/hr_recruitment/models/hr_recruitment.py b/addons/hr_recruitment/models/hr_recruitment.py index 765d13a2d525e0f4a4aff2eaf638d516680808da..6d41a839f3654fae9f3e28838df1a07f9d7aec68 100644 --- a/addons/hr_recruitment/models/hr_recruitment.py +++ b/addons/hr_recruitment/models/hr_recruitment.py @@ -377,7 +377,7 @@ class Applicant(models.Model): defaults.update(custom_values) return super(Applicant, self).message_new(msg, custom_values=defaults) - def _message_post_after_hook(self, message, values): + def _message_post_after_hook(self, message, values, notif_layout): if self.email_from and not self.partner_id: # we consider that posting a message with a specified recipient (not a follower, a specific one) # on a document without customer means that it was created through the chatter using @@ -388,7 +388,7 @@ class Applicant(models.Model): ('partner_id', '=', False), ('email_from', '=', new_partner.email), ('stage_id.fold', '=', False)]).write({'partner_id': new_partner.id}) - return super(Applicant, self)._message_post_after_hook(message, values) + return super(Applicant, self)._message_post_after_hook(message, values, notif_layout) @api.multi def create_employee_from_applicant(self): diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index 4c51c4e635e17b008fcef09c1ddf200d712b69fd..1973c204b133a6ebde9c8cf5c91dd7907908b8fe 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -803,7 +803,7 @@ class Message(models.Model): #------------------------------------------------------ @api.multi - def _notify(self, force_send=False, send_after_commit=True, user_signature=True): + def _notify(self, layout=False, force_send=False, send_after_commit=True, user_signature=True): """ Compute recipients to notify based on specified recipients and document followers. Delegate notification to partners to send emails and bus notifications and to channels to broadcast messages on channels """ @@ -854,7 +854,7 @@ class Message(models.Model): ('id', 'in', (partners_sudo - notif_partners).ids), ('channel_ids', 'in', email_channels.ids), ('email', '!=', self_sudo.author_id.email or self_sudo.email_from), - ])._notify(self, force_send=force_send, send_after_commit=send_after_commit, user_signature=user_signature) + ])._notify(self, layout=layout, force_send=force_send, send_after_commit=send_after_commit, user_signature=user_signature) notif_partners._notify_by_chat(self) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 4d9ff5f3369ba0e0d5da138dd2394a9067c10886..1473953a91b1cd9c734e35bf4f8d79cbd7f5b48f 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1759,9 +1759,10 @@ class MailThread(models.AbstractModel): @api.multi @api.returns('self', lambda value: value.id) - def message_post(self, body='', subject=None, message_type='notification', - subtype=None, parent_id=False, attachments=None, - content_subtype='html', **kwargs): + def message_post(self, body='', subject=None, + message_type='notification', subtype=None, + parent_id=False, attachments=None, content_subtype='html', + notif_layout=False, **kwargs): """ Post a new message in an existing thread, returning the new mail.message ID. :param int thread_id: thread ID to post into, or list with one ID; @@ -1886,15 +1887,16 @@ class MailThread(models.AbstractModel): # Post the message new_message = MailMessage.create(values) - self._message_post_after_hook(new_message, values) + self._message_post_after_hook(new_message, values, notif_layout) return new_message - def _message_post_after_hook(self, message, values): + def _message_post_after_hook(self, message, values, notif_layout): """ Hook to add custom behavior after having posted the message. Both message and computed value are given, to try to lessen query count by using already-computed values instead of having to rebrowse things. """ # Notify recipients of the newly-created message (Inbox / Email + channels) message._notify( + layout=notif_layout, force_send=self.env.context.get('mail_notify_force_send', True), user_signature=self.env.context.get('mail_notify_user_signature', True) ) diff --git a/addons/mail/models/res_partner.py b/addons/mail/models/res_partner.py index 77d61185ed032f1b6e03772cebaaad07d70108e4..7f9149a92553205590d702280661d17b9d2d65a6 100644 --- a/addons/mail/models/res_partner.py +++ b/addons/mail/models/res_partner.py @@ -147,7 +147,7 @@ class Partner(models.Model): }) @api.multi - def _notify(self, message, force_send=False, send_after_commit=True, user_signature=True): + def _notify(self, message, layout=False, force_send=False, send_after_commit=True, user_signature=True): """ Method to send email linked to notified messages. The recipients are the recordset on which this method is called. @@ -159,11 +159,17 @@ class Partner(models.Model): return True # existing custom notification email - base_template = None if message.model and self._context.get('custom_layout', False): - base_template = self.env.ref(self._context['custom_layout'], raise_if_not_found=False) - if not base_template: - base_template = self.env.ref('mail.mail_template_data_notification_email_default') + template_xmlid = self._context['custom_layout'] + elif layout: + template_xmlid = layout + else: + template_xmlid = 'mail.mail_template_data_notification_email_default' + try: + base_template = self.env.ref(template_xmlid, raise_if_not_found=True) + except ValueError: + _logger.warning('QWeb template %s not found when sending notification emails. Skipping.' % (template_xmlid)) + return False base_template_ctx = self._notify_prepare_template_context(message) if not user_signature: diff --git a/addons/project/models/project.py b/addons/project/models/project.py index 548013fae463b38f8c58521d62395c1b36bb5c52..34a3e5b5fa52fbc91e62b7995a39b8fb747f896c 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -985,7 +985,7 @@ class Task(models.Model): res['headers'] = repr(headers) return res - def _message_post_after_hook(self, message, values): + def _message_post_after_hook(self, message, values, notif_layout): if self.email_from and not self.partner_id: # we consider that posting a message with a specified recipient (not a follower, a specific one) # on a document without customer means that it was created through the chatter using @@ -996,7 +996,7 @@ class Task(models.Model): ('partner_id', '=', False), ('email_from', '=', new_partner.email), ('stage_id.fold', '=', False)]).write({'partner_id': new_partner.id}) - return super(Task, self)._message_post_after_hook(message, values) + return super(Task, self)._message_post_after_hook(message, values, notif_layout) def action_assign_to_me(self): self.write({'user_id': self.env.user.id}) diff --git a/addons/website_event_track/models/event_track.py b/addons/website_event_track/models/event_track.py index 3aeda823ced8e4d79626d10ab4679008c5f03c0b..ae02a039c4ea9abb9db0058808bb4c3665890d91 100644 --- a/addons/website_event_track/models/event_track.py +++ b/addons/website_event_track/models/event_track.py @@ -159,7 +159,7 @@ class Track(models.Model): track._message_add_suggested_recipient(recipients, email=track.partner_email, reason=_('Speaker Email')) return recipients - def _message_post_after_hook(self, message, values): + def _message_post_after_hook(self, message, values, notif_layout): if self.partner_email and not self.partner_id: # we consider that posting a message with a specified recipient (not a follower, a specific one) # on a document without customer means that it was created through the chatter using @@ -171,7 +171,7 @@ class Track(models.Model): ('partner_email', '=', new_partner.email), ('stage_id.is_cancel', '=', False), ]).write({'partner_id': new_partner.id}) - return super(Track, self)._message_post_after_hook(message, values) + return super(Track, self)._message_post_after_hook(message, values, notif_layout) @api.multi def open_track_speakers_list(self):