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.

76 lines
3.1 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. this._mail_follower_custom_notification_update()
  23. return this
  24. @api.multi
  25. def _mail_follower_custom_notification_update(self, subtypes=None):
  26. self.ensure_one()
  27. for subtype in subtypes or self.subtype_ids:
  28. if not subtype.res_model and\
  29. subtype.custom_notification_model_ids and\
  30. self.res_model not in\
  31. subtype.custom_notification_model_ids\
  32. .mapped('model'):
  33. continue
  34. user = self.env['res.users'].search([
  35. ('partner_id', '=', self.partner_id.id),
  36. ], limit=1)
  37. is_employee = user and user.has_group('base.group_user')
  38. if subtype.custom_notification_mail == 'force_yes':
  39. self.force_mail_subtype_ids |= subtype
  40. if subtype.custom_notification_mail == 'force_no':
  41. self.force_nomail_subtype_ids |= subtype
  42. if is_employee:
  43. if subtype.custom_notification_mail_employees == 'force_yes':
  44. self.force_mail_subtype_ids |= subtype
  45. self.force_nomail_subtype_ids -= subtype
  46. if subtype.custom_notification_mail_employees == 'force_no':
  47. self.force_mail_subtype_ids -= subtype
  48. self.force_nomail_subtype_ids |= subtype
  49. if subtype.custom_notification_own:
  50. self.force_own_subtype_ids |= subtype
  51. @api.multi
  52. def write(self, values):
  53. result = super(MailFollowers, self).write(values)
  54. if 'subtype_ids' in values:
  55. for this in self:
  56. subtypes = self.env['mail.message.subtype'].browse(
  57. filter(
  58. None,
  59. map(
  60. lambda x: x.get('id'),
  61. this.resolve_2many_commands(
  62. 'subtype_ids', values['subtype_ids'],
  63. ),
  64. )
  65. )
  66. )
  67. this._mail_follower_custom_notification_update(subtypes)
  68. return result