Skip to content

Commit

Permalink
[REF] mail: small method refactoring to ease chat integration
Browse files Browse the repository at this point in the history
  • Loading branch information
tde-banana-odoo committed Oct 1, 2015
1 parent 7bdee12 commit 86e50ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
11 changes: 1 addition & 10 deletions addons/mail/models/mail_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,17 +842,8 @@ def _notify(self, force_send=False, user_signature=True):
# 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
Expand Down
13 changes: 13 additions & 0 deletions addons/mail/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ def _notify_send(self, body, subject, recipients, **mail_values):

@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:
Expand Down

0 comments on commit 86e50ba

Please sign in to comment.