mirror of https://github.com/OCA/social.git
fixup! [IMP] mail_tracking: Failed Messages to 12.0
parent
322a3e0437
commit
714983bdae
|
@ -233,3 +233,24 @@ class MailMessage(models.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())
|
||||
|
||||
@api.model
|
||||
def set_all_as_reviewed(self):
|
||||
""" Sets all messages in the given domain as reviewed.
|
||||
Used by Discuss """
|
||||
|
||||
unreviewed_messages = self.search(self._get_failed_message_domain())
|
||||
unreviewed_messages.write({'mail_tracking_needs_action': False})
|
||||
ids = unreviewed_messages.ids
|
||||
|
||||
self.env['bus.bus'].sendone(
|
||||
(self._cr.dbname, 'res.partner',
|
||||
self.env.user.partner_id.id),
|
||||
{
|
||||
'type': 'toggle_tracking_status',
|
||||
'message_ids': ids,
|
||||
'needs_actions': False,
|
||||
}
|
||||
)
|
||||
|
||||
return ids
|
||||
|
|
|
@ -34,7 +34,14 @@ class MailResendMessage(models.TransientModel):
|
|||
to_send = wizard.partner_ids.filtered(lambda p: p.resend).mapped(
|
||||
"partner_id")
|
||||
if to_send:
|
||||
# Set as reviewed
|
||||
wizard.mail_message_id.mail_tracking_needs_action = False
|
||||
# Reset mail.tracking.email state
|
||||
tracking_ids = wizard.mail_message_id.mail_tracking_ids\
|
||||
.filtered(lambda x: x.partner_id in to_send)
|
||||
tracking_ids.write({'state': False})
|
||||
# Sen bus notification to update Discuss and
|
||||
# mail_failed_messages widget
|
||||
notifications = [
|
||||
[
|
||||
(self._cr.dbname, 'res.partner',
|
||||
|
|
|
@ -16,6 +16,7 @@ odoo.define('mail_tracking.FailedMessageDiscuss', function (require) {
|
|||
var MailManager = require('mail.Manager');
|
||||
var Mailbox = require('mail.model.Mailbox');
|
||||
var core = require('web.core');
|
||||
var session = require('web.session');
|
||||
|
||||
var QWeb = core.qweb;
|
||||
var _t = core._t;
|
||||
|
@ -128,7 +129,7 @@ odoo.define('mail_tracking.FailedMessageDiscuss', function (require) {
|
|||
var channelFailed = self.getMailbox('failed');
|
||||
channelFailed.invalidateCaches();
|
||||
}
|
||||
self._mailBus.trigger('update_message', message);
|
||||
self._mailBus.trigger('update_message', message, data.type);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -182,6 +183,63 @@ odoo.define('mail_tracking.FailedMessageDiscuss', function (require) {
|
|||
return $sidebar;
|
||||
},
|
||||
|
||||
/**
|
||||
* Overrides to listen click on 'Set all as reviewed' button
|
||||
*
|
||||
* @Override
|
||||
*/
|
||||
_renderButtons: function () {
|
||||
this._super.apply(this, arguments);
|
||||
this.$buttons
|
||||
.on('click', '.o_mail_discuss_button_set_all_reviewed',
|
||||
this._onSetAllAsReviewedClicked.bind(this));
|
||||
},
|
||||
|
||||
/**
|
||||
* Overrides to update 'set all as reviewed' button
|
||||
*
|
||||
* @Override
|
||||
*/
|
||||
_updateControlPanelButtons: function (thread) {
|
||||
// Set All Reviewed
|
||||
if (thread.getID() === 'mailbox_failed') {
|
||||
this.$buttons
|
||||
.find('.o_mail_discuss_button_set_all_reviewed')
|
||||
.removeClass('d-none d-md-inline-block')
|
||||
.addClass('d-none d-md-inline-block');
|
||||
} else {
|
||||
this.$buttons
|
||||
.find('.o_mail_discuss_button_set_all_reviewed')
|
||||
.removeClass('d-none d-md-inline-block')
|
||||
.addClass('d-none');
|
||||
}
|
||||
|
||||
this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* Overrides to update 'set all as reviewed' button
|
||||
*
|
||||
* @Override
|
||||
*/
|
||||
_updateButtonStatus: function (disabled, type) {
|
||||
if (this._thread.getID() === 'mailbox_failed') {
|
||||
this.$buttons
|
||||
.find('.o_mail_discuss_button_set_all_reviewed')
|
||||
.toggleClass('disabled', disabled);
|
||||
// Display Rainbowman when all inbox messages are reviewed
|
||||
// through 'TOGGLE TRACKING STATUS' or marking last failed
|
||||
// message as reviewed
|
||||
if (disabled && type === 'toggle_tracking_status') {
|
||||
this.trigger_up('show_effect', {
|
||||
message: _t(
|
||||
"Congratulations, your failed mailbox is empty"),
|
||||
type: 'rainbow_man',
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Overrides to update messages in 'failed' mailbox thread
|
||||
*
|
||||
|
@ -271,6 +329,13 @@ odoo.define('mail_tracking.FailedMessageDiscuss', function (require) {
|
|||
context: this.getSession().user_context,
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_onSetAllAsReviewedClicked: function () {
|
||||
this._thread.setAllMessagesAsReviewed();
|
||||
},
|
||||
});
|
||||
|
||||
MailManager.include({
|
||||
|
@ -302,11 +367,32 @@ odoo.define('mail_tracking.FailedMessageDiscuss', function (require) {
|
|||
return [
|
||||
['mail_tracking_ids.state', 'in', FAILED_STATES],
|
||||
['mail_tracking_needs_action', '=', true],
|
||||
'|',
|
||||
['partner_ids', 'in', [session.partner_id]],
|
||||
['author_id', '=', session.partner_id],
|
||||
];
|
||||
}
|
||||
// Workaround to avoid throw 'Missing domain' exception
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets all messages from the mailbox as reviewed. At the moment,
|
||||
* this method makes only sense for 'Failed'.
|
||||
*
|
||||
* @param {Array} domain
|
||||
* @returns {$.Promise} resolved when all messages have been marked as
|
||||
* reviewed on the server
|
||||
*/
|
||||
setAllMessagesAsReviewed: function () {
|
||||
if (this._id === 'mailbox_failed' && this.getMailboxCounter() > 0) {
|
||||
return this._rpc({
|
||||
model: 'mail.message',
|
||||
method: 'set_all_as_reviewed',
|
||||
});
|
||||
}
|
||||
return $.when();
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -301,8 +301,8 @@ odoo.define('mail_tracking.FailedMessage', function (require) {
|
|||
this._super.apply(this, arguments);
|
||||
this._enabledOptions.displayRetryButton = true;
|
||||
this._enabledOptions.displayReviewedButton = true;
|
||||
this._disabledOptions.displayRetryButton = true;
|
||||
this._disabledOptions.displayReviewedButton = true;
|
||||
this._disabledOptions.displayRetryButton = false;
|
||||
this._disabledOptions.displayReviewedButton = false;
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -25,4 +25,10 @@
|
|||
</t>
|
||||
</t>
|
||||
|
||||
<t t-extend="mail.discuss.ControlButtons">
|
||||
<t t-jquery="div" t-operation="append">
|
||||
<button type="button" class="btn btn-secondary o_mail_discuss_button_set_all_reviewed d-none d-md-inline-block" title="Mark all as reviewed">Mark all as reviewed</button>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
|
|
Loading…
Reference in New Issue