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.

46 lines
1.8 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 MailSubtypeAssignCustomNotifications(models.TransientModel):
  6. _name = 'mail.subtype.assign.custom.notifications'
  7. _description = 'Assign custom notification settings to existing followers'
  8. subtype_ids = fields.Many2many(
  9. 'mail.message.subtype', 'mail_subtype_assign_custom_notifications_rel',
  10. string='Subtypes', required=True,
  11. default=lambda self: [(6, 0, self.env.context.get('active_ids', []))])
  12. @api.multi
  13. def button_apply(self):
  14. self.ensure_one()
  15. for subtype in self.subtype_ids:
  16. domain = [('subtype_ids', '=', subtype.id)]
  17. if subtype.custom_notification_model_ids:
  18. domain.append(
  19. ('res_model', 'in',
  20. subtype.custom_notification_model_ids.mapped('model')))
  21. self.env['mail.followers'].with_context(active_test=False)\
  22. .search(domain)\
  23. .write({
  24. 'force_mail_subtype_ids': [
  25. (4, subtype.id)
  26. if subtype.custom_notification_mail == 'force_yes'
  27. else
  28. (3, subtype.id)
  29. ],
  30. 'force_nomail_subtype_ids': [
  31. (4, subtype.id)
  32. if subtype.custom_notification_mail == 'force_no'
  33. else
  34. (3, subtype.id)
  35. ],
  36. 'force_own_subtype_ids': [
  37. (4, subtype.id)
  38. if subtype.custom_notification_own
  39. else
  40. (3, subtype.id)
  41. ],
  42. })