[FIX][IMP] mail: update all notification status before sending bus notifications
Otherwise status of notifications is not correctly updated when sending them on the bus. Task ID 2068986
This commit is contained in:
@@ -157,18 +157,20 @@ class MailMail(models.Model):
|
||||
failed = self.env['mail.notification']
|
||||
if failure_type:
|
||||
failed = notifications.filtered(lambda notif: notif.res_partner_id not in success_pids)
|
||||
(notifications - failed).sudo().write({
|
||||
'notification_status': 'sent',
|
||||
'failure_type': '',
|
||||
'failure_reason': '',
|
||||
})
|
||||
if failed:
|
||||
failed.sudo().write({
|
||||
'notification_status': 'exception',
|
||||
'failure_type': failure_type,
|
||||
'failure_reason': failure_reason,
|
||||
})
|
||||
messages = notifications.mapped('mail_message_id').filtered(lambda m: m.is_thread_message())
|
||||
# TDE TODO: could be great to notify message-based, not notifications-based, to lessen number of notifs
|
||||
messages._notify_mail_failure_update() # notify user that we have a failure
|
||||
(notifications - failed).sudo().write({
|
||||
'notification_status': 'sent',
|
||||
'failure_type': '',
|
||||
'failure_reason': '',
|
||||
})
|
||||
if not failure_type or failure_type == 'RECIPIENT': # if we have another error, we want to keep the mail.
|
||||
mail_to_delete_ids = [mail.id for mail in self if mail.auto_delete]
|
||||
self.browse(mail_to_delete_ids).sudo().unlink()
|
||||
|
||||
Reference in New Issue
Block a user