From 5f9e8ff95e187da9ceb28e996601de8518c54539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20D=C3=ADaz?= Date: Thu, 14 Nov 2019 18:41:24 +0100 Subject: [PATCH] [FIX] mail_tracking: Refresh thread widget when sets a message as reviewed Previous this commit, failed messages widget data wasn't updated properly when you set as reviewed/retry the last message displayed. This commit resolve the problem and improves the "set as reviewed" action to avoid multi-user inconsistencies (don't toggle the value). --- mail_tracking/i18n/mail_tracking.pot | 4 +-- mail_tracking/models/mail_message.py | 13 ++++----- mail_tracking/models/mail_resend_message.py | 28 ++++++------------- .../static/src/js/failed_message/discuss.js | 11 ++++---- .../static/src/js/failed_message/thread.js | 6 ++-- mail_tracking/tests/test_mail_tracking.py | 2 +- 6 files changed, 27 insertions(+), 37 deletions(-) diff --git a/mail_tracking/i18n/mail_tracking.pot b/mail_tracking/i18n/mail_tracking.pot index 7cfc6d1..f60d778 100644 --- a/mail_tracking/i18n/mail_tracking.pot +++ b/mail_tracking/i18n/mail_tracking.pot @@ -92,7 +92,7 @@ msgstr "" #. module: mail_tracking #. openerp-web -#: code:addons/mail_tracking/static/src/js/failed_message/discuss.js:231 +#: code:addons/mail_tracking/static/src/js/failed_message/discuss.js:232 #, python-format msgid "Congratulations, your failed mailbox is empty" msgstr "" @@ -232,7 +232,7 @@ msgstr "" #. module: mail_tracking #. openerp-web -#: code:addons/mail_tracking/static/src/js/failed_message/discuss.js:350 +#: code:addons/mail_tracking/static/src/js/failed_message/discuss.js:351 #: code:addons/mail_tracking/static/src/xml/failed_message/discuss.xml:13 #: code:addons/mail_tracking/static/src/xml/failed_message/thread.xml:21 #: model_terms:ir.ui.view,arch_db:mail_tracking.view_mail_tracking_email_search diff --git a/mail_tracking/models/mail_message.py b/mail_tracking/models/mail_message.py index f552b7b..6f407c2 100644 --- a/mail_tracking/models/mail_message.py +++ b/mail_tracking/models/mail_message.py @@ -203,18 +203,17 @@ class MailMessage(models.Model): for msg in self.sorted('date', reverse=True)] @api.multi - def toggle_tracking_status(self): - """Toggle message tracking action. + def set_need_action_done(self): + """Set message tracking action as done - This will mark them to be (or not) ignored in the tracking issues - filter. + This will mark them to be ignored in the tracking issues filter. """ self.check_access_rule('read') - self.mail_tracking_needs_action = not self.mail_tracking_needs_action + self.write({'mail_tracking_needs_action': False}) notification = { 'type': 'toggle_tracking_status', - 'message_ids': [self.id], - 'needs_actions': self.mail_tracking_needs_action + 'message_ids': self.ids, + 'needs_actions': False } self.env['bus.bus'].sendone( (self._cr.dbname, 'res.partner', self.env.user.partner_id.id), diff --git a/mail_tracking/models/mail_resend_message.py b/mail_tracking/models/mail_resend_message.py index 555e30b..8758f97 100644 --- a/mail_tracking/models/mail_resend_message.py +++ b/mail_tracking/models/mail_resend_message.py @@ -42,23 +42,13 @@ class MailResendMessage(models.TransientModel): tracking_ids.write({'state': False}) # Send bus notifications to update Discuss and # mail_failed_messages widget - notifications = [ - [ - (self._cr.dbname, 'res.partner', - self.env.user.partner_id.id), - { - 'type': 'update_failed_messages', - } - ], - [ - (self._cr.dbname, 'res.partner', - self.env.user.partner_id.id), - { - 'type': 'toggle_tracking_status', - 'message_ids': [self.mail_message_id.id], - 'needs_actions': False, - } - ] - ] - self.env['bus.bus'].sendmany(notifications) + notification = { + 'type': 'toggle_tracking_status', + 'message_ids': [self.mail_message_id.id], + 'needs_actions': False + } + self.env['bus.bus'].sendone( + (self._cr.dbname, 'res.partner', + self.env.user.partner_id.id), + notification) super().resend_mail_action() diff --git a/mail_tracking/static/src/js/failed_message/discuss.js b/mail_tracking/static/src/js/failed_message/discuss.js index 715cc30..847443d 100644 --- a/mail_tracking/static/src/js/failed_message/discuss.js +++ b/mail_tracking/static/src/js/failed_message/discuss.js @@ -95,7 +95,7 @@ odoo.define('mail_tracking.FailedMessageDiscuss', function (require) { */ _handlePartnerNotification: function (data) { if (data.type === 'toggle_tracking_status') { - this._handlePartnerToggleFailedNotification(data); + this._handleChangeTrackingNeedsActionNotification(data); } else { // Workaround to avoid call '_handlePartnerChannelNotification' // because this is related with the failed mailbox, not a @@ -106,13 +106,14 @@ odoo.define('mail_tracking.FailedMessageDiscuss', function (require) { /** * This method updates messages in the failed mailbox when the flag - * 'mail_tracking_needs_action' is toggled. This can remove/add - * the message from/to failed mailbox and update mailbox counter. + * 'mail_tracking_needs_action' was changed to False. This can + * remove/add the message from/to failed mailbox and update mailbox + * counter. * * @private * @param {Object} data */ - _handlePartnerToggleFailedNotification: function (data) { + _handleChangeTrackingNeedsActionNotification: function (data) { var self = this; var failed = this.getMailbox('failed'); _.each(data.message_ids, function (messageID) { @@ -320,7 +321,7 @@ odoo.define('mail_tracking.FailedMessageDiscuss', function (require) { var messageID = $(event.currentTarget).data('message-id'); return this._rpc({ model: 'mail.message', - method: 'toggle_tracking_status', + method: 'set_need_action_done', args: [[messageID]], context: this.getSession().user_context, }); diff --git a/mail_tracking/static/src/js/failed_message/thread.js b/mail_tracking/static/src/js/failed_message/thread.js index 78e9ec6..652b881 100644 --- a/mail_tracking/static/src/js/failed_message/thread.js +++ b/mail_tracking/static/src/js/failed_message/thread.js @@ -26,7 +26,7 @@ odoo.define('mail_tracking.FailedMessageThread', function (require) { */ function _readMessages (widget, ids) { if (!ids.length) { - return $.when(); + return $.when([]); } var context = widget.record && widget.record.getContext(); return widget._rpc({ @@ -150,7 +150,7 @@ odoo.define('mail_tracking.FailedMessageThread', function (require) { _markFailedMessageReviewed: function (id) { return this._rpc({ model: 'mail.message', - method: 'toggle_tracking_status', + method: 'set_need_action_done', args: [[id]], context: this.record.getContext(), }); @@ -171,7 +171,7 @@ odoo.define('mail_tracking.FailedMessageThread', function (require) { var model = notif[0][1]; if (model === 'res.partner') { var data = notif[1]; - if (data.type === 'update_failed_messages') { + if (data.type === 'toggle_tracking_status') { // Reload 'mail_failed_message' widget self._reload({failed_message: true}); } diff --git a/mail_tracking/tests/test_mail_tracking.py b/mail_tracking/tests/test_mail_tracking.py index f9c6642..733e1bb 100644 --- a/mail_tracking/tests/test_mail_tracking.py +++ b/mail_tracking/tests/test_mail_tracking.py @@ -215,7 +215,7 @@ class TestMailTracking(TransactionCase): self.assertTrue(messages) self.assertTrue(messages_failed) self.assertTrue(len(messages) > len(messages_failed)) - tracking.mail_message_id.toggle_tracking_status() + tracking.mail_message_id.set_need_action_done() self.assertFalse(tracking.mail_message_id.mail_tracking_needs_action) self.assertTrue( MailMessageObj.get_failed_count() < failed_count)