[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
This commit is contained in:
XavierDo
2018-07-11 12:25:33 +02:00
parent 1b323e8b17
commit 62591c58f8
5 changed files with 69 additions and 2 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

+9
View File
@@ -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);
}
+1 -1
View File
@@ -237,7 +237,7 @@
</t>
<t t-raw="channel.last_message_preview"/>
</div>
<span t-att-data-channel_id="channel.id" t-att-data-res_id="channel.res_id" t-att-data-model="channel.model" title="Mark as Read" class="o_discuss_icon o_mail_channel_mark_read fa fa-check" t-if="channel.unread_counter"/>
<span t-att-data-channel_id="channel.id" t-att-data-res_id="channel.res_id" t-att-data-model="channel.model" t-att-data-unread_counter="channel.unread_counter" title="Mark as Read" class="o_discuss_icon o_mail_channel_mark_read fa fa-check" t-if="channel.unread_counter"/>
</div>
</div>
</t>
+34 -1
View File
@@ -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'}
@@ -29,6 +29,23 @@
</form>
</field>
</record>
<record id="mail_resend_cancel_view_form" model="ir.ui.view">
<field name="name">mail.resend.cancel.form</field>
<field name="model">mail.resend.cancel</field>
<field name="groups_id" eval="[(4,ref('base.group_user'))]"/>
<field name="arch" type="xml">
<form string="Cancel notification in failure">
<field name="model" invisible='1'/>
<field name="help_message"/>
<p>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.</p>
<img src="/mail/static/img/red_envelope.png"/>
<footer>
<button string="Discard delivery failures" name="cancel_resend_action" type="object" class="btn-primary" />
<button string="Cancel" class="btn-default" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="mail_resend_message_action" model="ir.actions.act_window">
<field name="name">Resend mail</field>
<field name="res_model">mail.resend.message</field>
@@ -37,6 +54,14 @@
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<record id="mail_resend_cancel_action" model="ir.actions.act_window">
<field name="name">Discard mail delivery failures</field>
<field name="res_model">mail.resend.cancel</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</odoo>