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.

52 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015 Therp BV <http://therp.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import api, fields, models
  5. class MailFollowers(models.Model):
  6. _inherit = 'mail.followers'
  7. force_mail_subtype_ids = fields.Many2many(
  8. 'mail.message.subtype', 'mail_followers_force_mail_rel',
  9. 'mail_followers_id', 'mail_message_subtype_id',
  10. string='Force mails from subtype')
  11. force_nomail_subtype_ids = fields.Many2many(
  12. 'mail.message.subtype', 'mail_followers_force_nomail_rel',
  13. 'mail_followers_id', 'mail_message_subtype_id',
  14. string='Force no mails from subtype')
  15. force_own_subtype_ids = fields.Many2many(
  16. 'mail.message.subtype', 'mail_followers_force_own_rel',
  17. 'mail_followers_id', 'mail_message_subtype_id',
  18. string='Force own mails from subtype')
  19. @api.model
  20. def create(self, values):
  21. this = super(MailFollowers, self).create(values)
  22. for subtype in this.subtype_ids:
  23. if not subtype.res_model and\
  24. subtype.custom_notification_model_ids and\
  25. this.res_model not in\
  26. subtype.custom_notification_model_ids\
  27. .mapped('model'):
  28. continue
  29. user = self.env['res.users'].search([
  30. ('partner_id', '=', this.partner_id.id),
  31. ], limit=1)
  32. is_employee = user and user.has_group('base.group_user')
  33. if subtype.custom_notification_mail == 'force_yes':
  34. this.force_mail_subtype_ids |= subtype
  35. if subtype.custom_notification_mail == 'force_no':
  36. this.force_nomail_subtype_ids |= subtype
  37. if is_employee:
  38. if subtype.custom_notification_mail_employees == 'force_yes':
  39. this.force_mail_subtype_ids |= subtype
  40. this.force_nomail_subtype_ids -= subtype
  41. if subtype.custom_notification_mail_employees == 'force_no':
  42. this.force_mail_subtype_ids -= subtype
  43. this.force_nomail_subtype_ids |= subtype
  44. if subtype.custom_notification_own:
  45. this.force_own_subtype_ids |= subtype
  46. return this