diff --git a/mail_tracking/demo/demo.xml b/mail_tracking/demo/demo.xml
index e90d45d53..2776509c1 100644
--- a/mail_tracking/demo/demo.xml
+++ b/mail_tracking/demo/demo.xml
@@ -14,6 +14,7 @@
wood.corner26@example.com
+
Message with CC
@@ -38,6 +39,7 @@
wood.corner26@example.com
+
Failed Message
@@ -62,6 +64,7 @@
jackson.group82@example.com
+
Failed Message
@@ -86,6 +89,7 @@
admin@example.com
+
Failed Message
diff --git a/mail_tracking/models/mail_message.py b/mail_tracking/models/mail_message.py
index da9452bc1..772a3d65c 100644
--- a/mail_tracking/models/mail_message.py
+++ b/mail_tracking/models/mail_message.py
@@ -5,6 +5,7 @@
from odoo import _, models, api, fields
from email.utils import getaddresses
from odoo.tools import email_split
+from odoo.osv import expression
class MailMessage(models.Model):
@@ -25,14 +26,17 @@ class MailMessage(models.Model):
" to filter tracking issues",
default=False,
)
- is_failed_message = fields.Boolean(compute="_compute_is_failed_message")
+ is_failed_message = fields.Boolean(
+ compute="_compute_is_failed_message",
+ search='_search_is_failed_message',
+ )
@api.model
def get_failed_states(self):
"""The 'failed' states of the message"""
return {'error', 'rejected', 'spam', 'bounced', 'soft-bounced'}
- @api.depends('mail_tracking_needs_action', 'author_id', 'partner_ids',
+ @api.depends('mail_tracking_needs_action', 'author_id', 'notification_ids',
'mail_tracking_ids.state')
def _compute_is_failed_message(self):
"""Compute 'is_failed_message' field for the active user"""
@@ -40,12 +44,35 @@ class MailMessage(models.Model):
for message in self:
needs_action = message.mail_tracking_needs_action
involves_me = self.env.user.partner_id in (
- message.author_id | message.partner_ids)
+ message.author_id | message.notification_ids.mapped('res_partner_id'))
has_failed_trackings = failed_states.intersection(
message.mapped("mail_tracking_ids.state"))
message.is_failed_message = bool(
needs_action and involves_me and has_failed_trackings)
+ def _search_is_failed_message(self, operator, value):
+ """Search for messages considered failed for the active user.
+ Be notice that 'notificacion_ids' is a record that change if
+ the user mark the message as readed.
+ """
+ # FIXME: Due to ORM issue with auto_join and 'OR' we construct the domain
+ # using an extra query to get valid results.
+ # For more information see: https://github.com/odoo/odoo/issues/25175
+ notification_partner_ids = self.search([
+ ('notification_ids.res_partner_id', '=', self.env.user.partner_id.id)
+ ])
+ return expression.normalize_domain([
+ (
+ 'mail_tracking_ids.state',
+ 'in' if value else 'not in',
+ list(self.get_failed_states())
+ ),
+ ('mail_tracking_needs_action', '=', True),
+ '|',
+ ('author_id', '=', self.env.user.partner_id.id),
+ ('id', 'in', notification_partner_ids.ids),
+ ])
+
def _tracking_status_map_get(self):
"""Map tracking states to be used in chatter"""
return {
@@ -247,19 +274,10 @@ class MailMessage(models.Model):
(self._cr.dbname, 'res.partner', self.env.user.partner_id.id),
notification)
- def _get_failed_message_domain(self):
- domain = self.env['mail.thread']._get_failed_message_domain()
- domain += [
- '|',
- ('partner_ids', 'in', [self.env.user.partner_id.id]),
- ('author_id', '=', self.env.user.partner_id.id),
- ]
- return domain
-
@api.model
def get_failed_count(self):
""" Gets the number of failed messages used on discuss mailbox item"""
- return self.search_count(self._get_failed_message_domain())
+ return self.search_count([("is_failed_message", "=", True)])
@api.model
def set_all_as_reviewed(self):
@@ -267,7 +285,7 @@ class MailMessage(models.Model):
Used by Discuss """
- unreviewed_messages = self.search(self._get_failed_message_domain())
+ unreviewed_messages = self.search([("is_failed_message", "=", True)])
unreviewed_messages.write({'mail_tracking_needs_action': False})
ids = unreviewed_messages.ids
diff --git a/mail_tracking/static/src/js/failed_message/discuss.js b/mail_tracking/static/src/js/failed_message/discuss.js
index 847443d87..ed07e3ff8 100644
--- a/mail_tracking/static/src/js/failed_message/discuss.js
+++ b/mail_tracking/static/src/js/failed_message/discuss.js
@@ -15,17 +15,12 @@ odoo.define('mail_tracking.FailedMessageDiscuss', function (require) {
var Discuss = require('mail.Discuss');
var MailManager = require('mail.Manager');
var Mailbox = require('mail.model.Mailbox');
+ var Dialog = require('web.Dialog');
var core = require('web.core');
- var session = require('web.session');
var QWeb = core.qweb;
var _t = core._t;
- /* The states to consider a message as failed message */
- var FAILED_STATES = [
- 'error', 'rejected', 'spam', 'bounced', 'soft-bounced',
- ];
-
AbstractMessage.include({
@@ -207,8 +202,11 @@ odoo.define('mail_tracking.FailedMessageDiscuss', function (require) {
_updateControlPanelButtons: function (thread) {
this.$btn_set_all_reviewed
.toggleClass(
- 'd-none d-md-none',
- thread.getID() !== 'mailbox_failed');
+ 'd-none',
+ thread.getID() !== 'mailbox_failed')
+ .toggleClass(
+ 'd-md-inline-block',
+ thread.getID() === 'mailbox_failed');
return this._super.apply(this, arguments);
},
@@ -333,7 +331,17 @@ odoo.define('mail_tracking.FailedMessageDiscuss', function (require) {
* @private
*/
_onSetAllAsReviewedClicked: function () {
- this._thread.setAllMessagesAsReviewed();
+ var self = this;
+ var failed = this.call('mail_service', 'getMailbox', 'failed');
+ var promptText = _.str.sprintf(
+ _t("Do you really want to mark as reviewed all the" +
+ " failed messages (%d)?"),
+ failed.getMailboxCounter());
+ Dialog.confirm(this, promptText, {
+ confirm_callback: function () {
+ self._thread.setAllMessagesAsReviewed();
+ },
+ });
},
});
@@ -363,13 +371,7 @@ odoo.define('mail_tracking.FailedMessageDiscuss', function (require) {
*/
_getThreadDomain: function () {
if (this._id === 'mailbox_failed') {
- return [
- ['mail_tracking_ids.state', 'in', FAILED_STATES],
- ['mail_tracking_needs_action', '=', true],
- '|',
- ['partner_ids', 'in', [session.partner_id]],
- ['author_id', '=', session.partner_id],
- ];
+ return [['is_failed_message', '=', true]];
}
// Workaround to avoid throw 'Missing domain' exception. Call _super
// without a valid (hard-coded) thread id causes that exeception.
diff --git a/mail_tracking/static/src/xml/failed_message/discuss.xml b/mail_tracking/static/src/xml/failed_message/discuss.xml
index 45fb1f5d8..288094d59 100644
--- a/mail_tracking/static/src/xml/failed_message/discuss.xml
+++ b/mail_tracking/static/src/xml/failed_message/discuss.xml
@@ -27,7 +27,7 @@
-
+
diff --git a/mail_tracking/tests/test_mail_tracking.py b/mail_tracking/tests/test_mail_tracking.py
index c66e51a5f..47fa428bf 100644
--- a/mail_tracking/tests/test_mail_tracking.py
+++ b/mail_tracking/tests/test_mail_tracking.py
@@ -277,8 +277,7 @@ class TestMailTracking(TransactionCase):
values = tracking.mail_message_id.get_failed_messages()
self.assertEqual(values[0]['id'], tracking.mail_message_id.id)
messages = MailMessageObj.search([])
- messages_failed = MailMessageObj.search(
- MailMessageObj._get_failed_message_domain())
+ messages_failed = MailMessageObj.search([['is_failed_message', '=', True]])
self.assertTrue(messages)
self.assertTrue(messages_failed)
self.assertTrue(len(messages) > len(messages_failed))