[REF] mail: small method refactoring to ease chat integration

This commit is contained in:
Thibault Delavallée
2015-10-01 16:36:24 +02:00
parent 7bdee12038
commit 86e50baefc
2 changed files with 14 additions and 10 deletions
+1 -10
View File
@@ -842,17 +842,8 @@ class Message(models.Model):
# update message
self.write({'channel_ids': [(6, 0, channels.ids)], 'needaction_partner_ids': [(6, 0, partners.ids)]})
# notify partners
# TDE TODO: model-dependant ? (like customer -> always email ?)
email_channels = channels.filtered(lambda channel: channel.email_send)
self.env['res.partner'].sudo().search([
'|',
('id', 'in', partners.ids),
('channel_ids', 'in', email_channels.ids),
('email', '!=', self_sudo.author_id and self_sudo.author_id.email or self.email_from),
('notify_email', '!=', 'none')]
)._notify(self, force_send=force_send, user_signature=user_signature)
# notify partners and channels
partners._notify(self, force_send=force_send, user_signature=user_signature)
channels._notify(self)
# Discard cache, because child / parent allow reading and therefore
+13
View File
@@ -115,6 +115,19 @@ class Partner(models.Model):
@api.multi
def _notify(self, message, force_send=False, user_signature=True):
# TDE TODO: model-dependant ? (like customer -> always email ?)
message_sudo = message.sudo()
email_channels = message.channel_ids.filtered(lambda channel: channel.email_send)
self.sudo().search([
'|',
('id', 'in', self.ids),
('channel_ids', 'in', email_channels.ids),
('email', '!=', message_sudo.author_id and message_sudo.author_id.email or message.email_from),
('notify_email', '!=', 'none')])._notify_by_email(message, force_send=force_send, user_signature=user_signature)
return True
@api.multi
def _notify_by_email(self, message, force_send=False, user_signature=True):
""" Method to send email linked to notified messages. The recipients are
the recordset on which this method is called. """
if not self.ids: