diff --git a/addons/mail/static/img/red_envelope.png b/addons/mail/static/img/red_envelope.png new file mode 100644 index 00000000000..8a6152ae5de Binary files /dev/null and b/addons/mail/static/img/red_envelope.png differ diff --git a/addons/mail/static/src/js/systray.js b/addons/mail/static/src/js/systray.js index 18e9511cf25..f354d2ec6f7 100644 --- a/addons/mail/static/src/js/systray.js +++ b/addons/mail/static/src/js/systray.js @@ -207,6 +207,15 @@ var MessagingMenu = Widget.extend({ var model = $(ev.currentTarget).data('model'); var domain = [['model', '=', model], ['res_id', '=', resID]]; this.call('chat_manager', 'markAllAsRead', channel, domain); + } else if (channelID === 'mail_failure') { + var unread_counter = $(ev.currentTarget).data('unread_counter'); + var model = $(ev.currentTarget).data('model'); + this.do_action('mail.mail_resend_cancel_action', { + additional_context: { + default_model: model, + unread_counter: unread_counter + } + }); } else { this.call('chat_manager', 'markChannelAsSeen', channel); } diff --git a/addons/mail/static/src/xml/discuss.xml b/addons/mail/static/src/xml/discuss.xml index 1eda1dfec1b..f1fef247c7c 100644 --- a/addons/mail/static/src/xml/discuss.xml +++ b/addons/mail/static/src/xml/discuss.xml @@ -237,7 +237,7 @@ - + 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'} diff --git a/addons/mail/wizard/mail_resend_message_views.xml b/addons/mail/wizard/mail_resend_message_views.xml index 970b56636b5..b0e6f1ade83 100644 --- a/addons/mail/wizard/mail_resend_message_views.xml +++ b/addons/mail/wizard/mail_resend_message_views.xml @@ -29,6 +29,23 @@ + + mail.resend.cancel.form + mail.resend.cancel + + + + + + If you want to re-send them, click Cancel now, then click on the notification and review them one by one by clicking on the red envelope next to each message. + + + + + Resend mail mail.resend.message @@ -37,6 +54,14 @@ form new + + Discard mail delivery failures + mail.resend.cancel + ir.actions.act_window + form + form + new +
If you want to re-send them, click Cancel now, then click on the notification and review them one by one by clicking on the red envelope next to each message.