Files
odoo_source/addons/mail/wizard/mail_resend_cancel.py
T
Anh Thao Pham (pta) 5184eedc0e [FIX] mail: fix cancelling of email failures
- Configure your outgoing email server to be sure that a failure will be triggered
  when trying to send an email
- Make sure you don't have enough sms credit to send a sms
- Go to a contact page
- Send a message to the contact via the chatter
- An notification error should appear in the conversations icon in the systray
- Send a sms to the contact
- An notification error should appear in the conversations icon in the systray
- Click on the "Mark as read" icon on the notification error for the email
- A "Discard mail delivery failures" wizard will appear
- Click on "DISCARD DELIVERY FAILURES"
All email and sms delivery failures are discarded.
Only the email delivery failures should be discarded.

opw-2247617

closes odoo/odoo#51204

X-original-commit: d8c177969239a9bd6dcbd6654a914d40a6ba479f
Signed-off-by: Jorge Pinna Puissant (jpp) <jpp@odoo.com>
2020-05-13 16:44:13 +00:00

38 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import _, api, fields, models
class MailResendCancel(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.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'))
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.notification_type = 'email' AND notif.notification_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({'notification_status': 'canceled'})
self.env["mail.message"].browse(messages_ids)._notify_message_notification_update()
return {'type': 'ir.actions.act_window_close'}