mail_group_message_reject.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import api, fields, models, tools, _
  4. class MailGroupMessageReject(models.TransientModel):
  5. _name = 'mail.group.message.reject'
  6. _description = 'Reject Group Message'
  7. subject = fields.Char('Subject', store=True, readonly=False, compute='_compute_subject')
  8. body = fields.Html('Contents', default='', sanitize_style=True)
  9. email_from_normalized = fields.Char('Email From', related='mail_group_message_id.email_from_normalized')
  10. mail_group_message_id = fields.Many2one('mail.group.message', string="Message", required=True, readonly=True)
  11. action = fields.Selection([('reject', 'Reject'), ('ban', 'Ban')], string='Action', required=True)
  12. send_email = fields.Boolean('Send Email', help='Send an email to the author of the message', compute='_compute_send_email')
  13. @api.depends('mail_group_message_id')
  14. def _compute_subject(self):
  15. for wizard in self:
  16. wizard.subject = _('Re: %s', wizard.mail_group_message_id.subject or '')
  17. @api.depends('body')
  18. def _compute_send_email(self):
  19. for wizard in self:
  20. wizard.send_email = not tools.is_html_empty(wizard.body)
  21. def action_send_mail(self):
  22. self.ensure_one()
  23. # Reject
  24. if self.action == 'reject' and self.send_email:
  25. self.mail_group_message_id.action_moderate_reject_with_comment(self.subject, self.body)
  26. elif self.action == 'reject' and not self.send_email:
  27. self.mail_group_message_id.action_moderate_reject()
  28. # Ban
  29. elif self.action == 'ban' and self.send_email:
  30. self.mail_group_message_id.action_moderate_ban_with_comment(self.subject, self.body)
  31. elif self.action == 'ban' and not self.send_email:
  32. self.mail_group_message_id.action_moderate_ban()