diff options
| author | XavierDo <xdo@odoo.com> | 2018-04-27 16:50:03 +0200 |
|---|---|---|
| committer | XavierDo <xdo@odoo.com> | 2018-06-07 11:46:28 +0200 |
| commit | 133eeb1bbf52e9a9ee58f83be8e7f0aba3c6d1ad (patch) | |
| tree | cd7c6b0a3c931705158c9af590206130480426f6 /addons/mail/models/mail_thread.py | |
| parent | aa7fb8c72317e330bbeb6ce29b4aace8627ef1d7 (diff) | |
[ADD] mail, mass_mailing: allow a user to resend a mail with failures
When a mail is in failure state, a red envelope appears next to the message
in a thread but it was difficult to send the mail again.
This tasks will allow users to send mail again easily, or mark notification
as cancelled if the user want to ignore this failure.
A notification will appear in sender systray while mail are in failure.
Task: #46158
PR: #24628
Diffstat (limited to 'addons/mail/models/mail_thread.py')
| -rw-r--r-- | addons/mail/models/mail_thread.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 4cde154e1cb..4f89da3b69e 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -102,6 +102,12 @@ class MailThread(models.AbstractModel): message_needaction_counter = fields.Integer( 'Number of Actions', compute='_get_message_needaction', help="Number of messages which requires an action") + message_has_error = fields.Boolean( + 'Message Delivery error', compute='_compute_message_has_error', search='_search_message_has_error', + help="If checked, some messages have a delivery error.") + message_has_error_counter = fields.Integer( + 'Number of error', compute='_compute_message_has_error', + help="Number of messages with delivery error") @api.one @api.depends('message_follower_ids') @@ -208,6 +214,26 @@ class MailThread(models.AbstractModel): def _search_message_needaction(self, operator, operand): return [('message_ids.needaction', operator, operand)] + @api.multi + def _compute_message_has_error(self): + self._cr.execute(""" SELECT msg.res_id, COUNT(msg.res_id) FROM mail_message msg + RIGHT JOIN mail_message_res_partner_needaction_rel rel + ON rel.mail_message_id = msg.id AND rel.email_status in ('exception','bounce') + WHERE msg.author_id = %s AND msg.model = %s AND msg.res_id in %s + GROUP BY msg.res_id""", + (self.env.user.partner_id.id, self._name, tuple(self.ids),)) + res = dict() + for result in self._cr.fetchall(): + res[result[0]] = result[1] + + for record in self: + record.message_has_error_counter = res.get(record.id, 0) + record.message_has_error = bool(record.message_has_error_counter) + + @api.model + def _search_message_has_error(self, operator, operand): + return [('message_ids.has_error', operator, operand)] + # ------------------------------------------------------ # CRUD overrides for automatic subscription and logging # ------------------------------------------------------ |
