You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 Therp BV <https://therp.nl>
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. from odoo import api, models
  5. class ResPartner(models.Model):
  6. _inherit = 'res.partner'
  7. @api.multi
  8. def _notify_by_email(
  9. self, message, force_send=False, send_after_commit=True,
  10. user_signature=True,
  11. ):
  12. """remove partners from `self` who requested not to be mailed,
  13. add the ones who did the opposite"""
  14. domain = [
  15. ('res_model', '=', message.model),
  16. ('res_id', '=', message.res_id),
  17. ]
  18. self |= self.env['mail.followers'].search(
  19. domain + [('force_mail_subtype_ids', '=', message.subtype_id.id)]
  20. ).mapped('partner_id')
  21. self -= self.env['mail.followers'].search(
  22. domain + [('force_nomail_subtype_ids', '=', message.subtype_id.id)]
  23. ).mapped('partner_id')
  24. return super(ResPartner, self)._notify_by_email(
  25. message, force_send=force_send,
  26. send_after_commit=send_after_commit, user_signature=user_signature,
  27. )