mirror of https://github.com/OCA/social.git
[IMP] mail_tracking: mail.thread filter for tracking errors
- Any model inheriting from mail.thread will have a filter available to obtain records with errors in their messages trackings. - The messages can be marked as done to avoid false positives when the issues are solved.pull/411/head
parent
abbd2a0eb8
commit
15d86bed66
|
@ -1,6 +1,7 @@
|
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import ir_mail_server
|
||||
from . import mail_thread
|
||||
from . import mail_mail
|
||||
from . import mail_message
|
||||
from . import mail_tracking_email
|
||||
|
|
|
@ -9,9 +9,20 @@ from odoo.tools import email_split
|
|||
class MailMessage(models.Model):
|
||||
_inherit = "mail.message"
|
||||
|
||||
|
||||
# Recipients
|
||||
email_cc = fields.Char("Cc", help='Additional recipients that receive a '
|
||||
'"Carbon Copy" of the e-mail')
|
||||
mail_tracking_ids = fields.One2many(
|
||||
comodel_name='mail.tracking.email',
|
||||
inverse_name='mail_message_id',
|
||||
string="Mail Trackings Associated with this message",
|
||||
)
|
||||
track_needs_action = fields.Boolean(
|
||||
string="The message tracking will be considered"
|
||||
"for filter tracking issues",
|
||||
default=True,
|
||||
)
|
||||
|
||||
def _tracking_status_map_get(self):
|
||||
return {
|
||||
|
@ -123,3 +134,11 @@ class MailMessage(models.Model):
|
|||
message_dict['partner_trackings'] = \
|
||||
partner_trackings[mail_message_id]
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def toggle_tracking_status(self):
|
||||
"""Toggle message tracking action needed to ignore them in the tracking
|
||||
issues filter"""
|
||||
# a user should always be able to star a message he can read
|
||||
self.check_access_rule('read')
|
||||
self.track_needs_action = not self.track_needs_action
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
from odoo import models, api, _
|
||||
from email.utils import getaddresses
|
||||
from odoo.tools import email_split_and_format
|
||||
from lxml import etree
|
||||
|
||||
|
||||
class MailThread(models.AbstractModel):
|
||||
|
@ -46,4 +47,33 @@ class MailThread(models.AbstractModel):
|
|||
partner = ResPartnerObj.browse(partner_id, self._prefetch)
|
||||
record._message_add_suggested_recipient(
|
||||
res, partner=partner, reason=_('Cc'))
|
||||
|
||||
@api.model
|
||||
def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
|
||||
submenu=False):
|
||||
"""Add a filter to any model with mail.thread that will show up records
|
||||
with tracking errors.
|
||||
"""
|
||||
res = super().fields_view_get(
|
||||
view_id=view_id, view_type=view_type, toolbar=toolbar,
|
||||
submenu=submenu)
|
||||
if view_type != 'search':
|
||||
return res
|
||||
eview = etree.fromstring(res['arch'])
|
||||
search_view = eview.xpath("//search")
|
||||
filter_name = "message_ids_with_tracking_errors"
|
||||
tracking_error_domain = """[
|
||||
("message_ids.tracking_ids.state", "in",
|
||||
"['error, 'rejected', 'spam', 'bounced', 'soft-bounced']"),
|
||||
("message_ids.track_needs_action", "=", True)
|
||||
]"""
|
||||
new_filter = etree.Element(
|
||||
'filter', {
|
||||
'string': _('Messages with errors'),
|
||||
'name': filter_name,
|
||||
'domain': tracking_error_domain})
|
||||
separator = etree.Element('separator', {})
|
||||
new_filter.append(separator)
|
||||
search_view.append(new_filter)
|
||||
res['arch'] = etree.tostring(eview)
|
||||
return res
|
||||
|
|
|
@ -19,12 +19,23 @@ odoo.define('mail_tracking.partner_tracking', function (require) {
|
|||
msg.partner_trackings = data.partner_trackings || [];
|
||||
return msg;
|
||||
};
|
||||
chat_manager.toggle_tracking_status = function (message_id) {
|
||||
return this._rpc({
|
||||
model: 'mail.message',
|
||||
method: 'toggle_tracking_status',
|
||||
args: [[message_id]],
|
||||
});
|
||||
},
|
||||
|
||||
ChatThread.include({
|
||||
events: _.extend(ChatThread.prototype.events, {
|
||||
'click .o_mail_action_tracking_partner':
|
||||
'on_tracking_partner_click',
|
||||
'click .o_mail_action_tracking_status': 'on_tracking_status_click',
|
||||
'click .o_thread_message_tracking': function (event) {
|
||||
var message_id = $(event.currentTarget).data('message-id');
|
||||
this.trigger("toggle_tracking_status", message_id);
|
||||
},
|
||||
}),
|
||||
_preprocess_message: function () {
|
||||
var msg = this._super.apply(this, arguments);
|
||||
|
|
|
@ -47,6 +47,10 @@
|
|||
</t>
|
||||
|
||||
<t t-extend="mail.ChatThread.Message">
|
||||
<t t-jquery="span[class='o_thread_icons']" t-operation="inside">
|
||||
<i t-att-class="'fa fa-lg o_thread_icon o_thread_message_tracking ' + (message.track_needs_action ? 'fa-check-square' : 'fa-square-o')"
|
||||
t-att-data-message-id="message.id" title="Trackin reviewed"/>
|
||||
</t>
|
||||
<t t-jquery="p[class='o_mail_info']" t-operation="after">
|
||||
<p class="o_mail_tracking">
|
||||
<strong>To:</strong>
|
||||
|
|
Loading…
Reference in New Issue