diff options
| author | XavierDo <xdo@odoo.com> | 2018-06-26 11:17:21 +0200 |
|---|---|---|
| committer | XavierDo <xdo@odoo.com> | 2018-07-11 12:25:33 +0200 |
| commit | 62591c58f8abded96b5fedcc4d9760550b7bdf18 (patch) | |
| tree | c4e607fc4bf7498ce838fb7faf619b4a4c605c07 /addons/mail/wizard/mail_resend_message.py | |
| parent | 1b323e8b173e622adebdf2c6c2df8de759d83714 (diff) | |
[FIX] mail: add ability to mark failure notification as read
The mark as read button was not working for mail failure. More than that,
we wanted a functionnality to be able to massively mark mail failure as canceled,
especially to be able to clean databases from failure after migration.
Task: #1860054
PR: #25622
Diffstat (limited to 'addons/mail/wizard/mail_resend_message.py')
| -rw-r--r-- | addons/mail/wizard/mail_resend_message.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/addons/mail/wizard/mail_resend_message.py b/addons/mail/wizard/mail_resend_message.py index 2f3890755c1..f637b0ca737 100644 --- a/addons/mail/wizard/mail_resend_message.py +++ b/addons/mail/wizard/mail_resend_message.py @@ -70,7 +70,6 @@ class MailResendMessage(models.TransientModel): return {'type': 'ir.actions.act_window_close'} - class PartnerResend(models.TransientModel): _name = 'mail.resend.partner' _description = 'Partner with additionnal information for mail resend' @@ -82,3 +81,37 @@ class PartnerResend(models.TransientModel): resend_wizard_id = fields.Many2one('mail.resend.message', string="Resend wizard") message = fields.Char(string="Help message") + +class MailCancelResend(models.TransientModel): + _name = 'mail.resend.cancel' + _description = 'Dismiss notification for resend by model' + + model = fields.Char(string='Model') + help_message = fields.Char(string='Help message', compute='_compute_help_message') + + @api.multi + @api.depends('model') + def _compute_help_message(self): + for wizard in self: + wizard.help_message = _("Are you sure you want to discard %s mail delivery failures. You won't be able to re-send these mails later!") % (wizard._context.get('unread_counter')) + + @api.multi + def cancel_resend_action(self): + author_id = self.env.user.partner_id.id + for wizard in self: + self._cr.execute(""" + SELECT notif.id, mes.id + FROM mail_message_res_partner_needaction_rel notif + JOIN mail_message mes + ON notif.mail_message_id = mes.id + WHERE notif.email_status IN ('bounce', 'exception') + AND mes.model = %s + AND mes.author_id = %s + """, (wizard.model, author_id)) + res = self._cr.fetchall() + notif_ids = [row[0] for row in res] + messages_ids = list(set([row[1] for row in res])) + if notif_ids: + self.env["mail.notification"].browse(notif_ids).sudo().write({'email_status': 'canceled'}) + self.env["mail.message"].browse(messages_ids)._notify_failure_update() + return {'type': 'ir.actions.act_window_close'} |
