summaryrefslogtreecommitdiff
path: root/addons/mail
diff options
context:
space:
mode:
authorXavierDo <xdo@odoo.com>2018-06-26 11:17:21 +0200
committerXavierDo <xdo@odoo.com>2018-07-11 12:25:33 +0200
commit62591c58f8abded96b5fedcc4d9760550b7bdf18 (patch)
treec4e607fc4bf7498ce838fb7faf619b4a4c605c07 /addons/mail
parent1b323e8b173e622adebdf2c6c2df8de759d83714 (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')
-rw-r--r--addons/mail/static/img/red_envelope.pngbin0 -> 7074 bytes
-rw-r--r--addons/mail/static/src/js/systray.js9
-rw-r--r--addons/mail/static/src/xml/discuss.xml2
-rw-r--r--addons/mail/wizard/mail_resend_message.py35
-rw-r--r--addons/mail/wizard/mail_resend_message_views.xml25
5 files changed, 69 insertions, 2 deletions
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
--- /dev/null
+++ b/addons/mail/static/img/red_envelope.png
Binary files 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 @@
</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>
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 @@
</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>