[IMP] mail_tracking: black, isort, prettier

This commit is contained in:
Areeb Siddiqi 2021-05-03 12:53:26 -04:00 committed by Jasmin Solanki
parent 5b5a0f04f2
commit c721351a9c
7 changed files with 72 additions and 71 deletions

View File

@ -5,7 +5,7 @@ from odoo import fields, models
class MailBouncedMixin(models.AbstractModel):
""" A mixin class to use if you want to add is_bounced flag on a model.
"""A mixin class to use if you want to add is_bounced flag on a model.
The field '_primary_email' must be overridden in the model that inherit
the mixin and must contain the email field of the model.
"""

View File

@ -30,7 +30,7 @@ class MailMail(models.Model):
def _send_prepare_values(self, partner=None):
"""Creates the mail.tracking.email record and adds the image tracking
to the email"""
to the email"""
email = super()._send_prepare_values(partner=partner)
vals = self._tracking_email_prepare(partner, email)
tracking_email = self.env["mail.tracking.email"].sudo().create(vals)

View File

@ -27,7 +27,8 @@ class MailMessage(models.Model):
default=False,
)
is_failed_message = fields.Boolean(
compute="_compute_is_failed_message", search="_search_is_failed_message",
compute="_compute_is_failed_message",
search="_search_is_failed_message",
)
@api.model
@ -258,7 +259,7 @@ class MailMessage(models.Model):
def get_failed_messages(self):
"""Returns the list of failed messages to be used by the
failed_messages widget"""
failed_messages widget"""
return [
msg._prepare_dict_failed_message()
for msg in self.sorted("date", reverse=True)
@ -287,9 +288,9 @@ class MailMessage(models.Model):
@api.model
def set_all_as_reviewed(self):
""" Sets all messages in the given domain as reviewed.
"""Sets all messages in the given domain as reviewed.
Used by Discuss """
Used by Discuss"""
unreviewed_messages = self.search([("is_failed_message", "=", True)])
unreviewed_messages.write({"mail_tracking_needs_action": False})

View File

@ -22,7 +22,7 @@ class MailThread(models.AbstractModel):
def _get_failed_message_domain(self):
"""Domain used to display failed messages on the 'failed_messages'
widget"""
widget"""
failed_states = self.env["mail.message"].get_failed_states()
return [
("mail_tracking_needs_action", "=", True),

View File

@ -1,6 +1,6 @@
/* Copyright 2019 Alexandre Díaz
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). */
odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
odoo.define("mail_tracking.FailedMessageDiscuss", function (require) {
"use strict";
// To be considered:
@ -28,7 +28,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @returns {Boolean}
*/
isFailed: function() {
isFailed: function () {
return false;
},
});
@ -39,7 +39,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @override
*/
init: function(parent, data) {
init: function (parent, data) {
this._isFailedMessage = data.is_failed_message;
return this._super.apply(this, arguments);
},
@ -50,7 +50,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @override
*/
isFailed: function() {
isFailed: function () {
return _.contains(this._threadIDs, "mailbox_failed");
},
@ -59,7 +59,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @param {Boolean} failed
*/
setFailed: function(failed) {
setFailed: function (failed) {
if (failed) {
this._addThread("mailbox_failed");
} else {
@ -72,7 +72,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @override
*/
_processMailboxes: function() {
_processMailboxes: function () {
this.setFailed(this._isFailedMessage);
return this._super.apply(this, arguments);
},
@ -84,7 +84,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @override
*/
_handlePartnerNotification: function(data) {
_handlePartnerNotification: function (data) {
if (data.type === "toggle_tracking_status") {
this._handleChangeTrackingNeedsActionNotification(data);
} else {
@ -104,11 +104,11 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
* @private
* @param {Object} data
*/
_handleChangeTrackingNeedsActionNotification: function(data) {
_handleChangeTrackingNeedsActionNotification: function (data) {
var self = this;
var failed = this.getMailbox("failed");
_.each(data.message_ids, function(messageID) {
var message = _.find(self._messages, function(msg) {
_.each(data.message_ids, function (messageID) {
var message = _.find(self._messages, function (msg) {
return msg.getID() === messageID;
});
if (message) {
@ -149,7 +149,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
* @private
* @returns {Object}
*/
_sidebarQWebParams: function() {
_sidebarQWebParams: function () {
var failed = this.call("mail_service", "getMailbox", "failed");
return {
activeThreadID: this._thread ? this._thread.getID() : undefined,
@ -163,7 +163,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @override
*/
_renderSidebar: function() {
_renderSidebar: function () {
var $sidebar = this._super.apply(this, arguments);
// Because Odoo implementation isn't designed to be inherited
// properly, we inject 'failed' button using jQuery.
@ -182,7 +182,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @override
*/
_renderSidebarMailboxes: function() {
_renderSidebarMailboxes: function () {
this._super.apply(this, arguments);
this.$(".o_mail_discuss_sidebar_mailboxes").append(
QWeb.render("mail_tracking.SidebarFailed", this._sidebarQWebParams())
@ -194,7 +194,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @override
*/
_renderButtons: function() {
_renderButtons: function () {
this._super.apply(this, arguments);
this.$btn_set_all_reviewed = this.$buttons.find(
".o_mail_discuss_button_set_all_reviewed"
@ -212,7 +212,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @override
*/
_updateControlPanelButtons: function(thread) {
_updateControlPanelButtons: function (thread) {
this.$btn_set_all_reviewed
.toggleClass("d-none", thread.getID() !== "mailbox_failed")
.toggleClass("d-md-inline-block", thread.getID() === "mailbox_failed");
@ -227,7 +227,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @override
*/
_updateButtonStatus: function(disabled, type) {
_updateButtonStatus: function (disabled, type) {
if (this._thread.getID() === "mailbox_failed") {
this.$btn_set_all_reviewed.toggleClass("disabled", disabled);
// Display Rainbowman when all failed messages are reviewed
@ -247,15 +247,15 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @override
*/
_onMessageUpdated: function(message, type) {
_onMessageUpdated: function (message, type) {
var self = this;
var currentThreadID = this._thread.getID();
if (currentThreadID === "mailbox_failed" && !message.isFailed()) {
this._thread.fetchMessages(this.domain).then(function() {
this._thread.fetchMessages(this.domain).then(function () {
var options = self._getThreadRenderingOptions();
self._threadWidget
.removeMessageAndRender(message.getID(), self._thread, options)
.then(function() {
.then(function () {
self._updateButtonStatus(!self._thread.hasMessages(), type);
});
});
@ -273,7 +273,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @override
*/
_getThreadRenderingOptions: function() {
_getThreadRenderingOptions: function () {
var values = this._super.apply(this, arguments);
if (this._thread.getID() === "mailbox_failed") {
values.displayEmailIcons = true;
@ -289,7 +289,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @override
*/
_startListening: function() {
_startListening: function () {
this._super.apply(this, arguments);
this.call("mail_service", "getMailBus").on(
"update_failed",
@ -305,7 +305,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
* @private
* @param {Event} event
*/
_onRetryFailedMessage: function(event) {
_onRetryFailedMessage: function (event) {
event.preventDefault();
var messageID = $(event.currentTarget).data("message-id");
this.do_action("mail.mail_resend_message_action", {
@ -322,7 +322,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
* @param {Event} event
* @returns {Promise}
*/
_onMarkFailedMessageReviewed: function(event) {
_onMarkFailedMessageReviewed: function (event) {
event.preventDefault();
var messageID = $(event.currentTarget).data("message-id");
return this._rpc({
@ -338,7 +338,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @private
*/
_onSetAllAsReviewedClicked: function() {
_onSetAllAsReviewedClicked: function () {
var self = this;
var failed = this.call("mail_service", "getMailbox", "failed");
var failed_counter = failed.getMailboxCounter();
@ -351,7 +351,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
failed_counter
);
Dialog.confirm(this, promptText, {
confirm_callback: function() {
confirm_callback: function () {
self._thread.setAllMessagesAsReviewed();
},
});
@ -365,7 +365,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @override
*/
_updateMailboxesFromServer: function(data) {
_updateMailboxesFromServer: function (data) {
this._super.apply(this, arguments);
this._addMailbox({
id: "failed",
@ -381,7 +381,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
*
* @override
*/
_getThreadDomain: function() {
_getThreadDomain: function () {
if (this._id === "mailbox_failed") {
return [["is_failed_message", "=", true]];
}
@ -398,7 +398,7 @@ odoo.define("mail_tracking.FailedMessageDiscuss", function(require) {
* @returns {$.Promise} resolved when all messages have been marked as
* reviewed on the server
*/
setAllMessagesAsReviewed: function() {
setAllMessagesAsReviewed: function () {
if (this._id === "mailbox_failed" && this.getMailboxCounter() > 0) {
return this._rpc({
model: "mail.message",

View File

@ -1,6 +1,6 @@
/* Copyright 2019 Alexandre Díaz
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). */
odoo.define("mail_tracking.FailedMessageThread", function(require) {
odoo.define("mail_tracking.FailedMessageThread", function (require) {
"use strict";
var AbstractField = require("web.AbstractField");
@ -35,9 +35,9 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
args: [ids],
context: context || widget.getSession().user_context,
})
.then(function(messages) {
.then(function (messages) {
// Convert date to moment
_.each(messages, function(msg) {
_.each(messages, function (msg) {
msg.date = moment(time.auto_str_to_date(msg.date));
msg.hour = utils.timeFromNow(msg.date);
});
@ -54,7 +54,7 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
* @param {String} fieldName
* @returns {Array}
*/
_fetchSpecialFailedMessages: function(record, fieldName) {
_fetchSpecialFailedMessages: function (record, fieldName) {
var localID =
record._changes && fieldName in record._changes
? record._changes[fieldName]
@ -76,7 +76,7 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
*
* @override
*/
init: function() {
init: function () {
this._super.apply(this, arguments);
this.failed_messages = this.record.specialData[this.name] || [];
},
@ -86,7 +86,7 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
*
* @override
*/
start: function() {
start: function () {
this._super.apply(this, arguments);
this.call("bus_service", "onNotification", this, this._onNotification);
},
@ -97,7 +97,7 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
* @private
* @returns {Object}
*/
_failedItemsQWebParams: function() {
_failedItemsQWebParams: function () {
return {
failed_messages: this.failed_messages,
nbFailedMessages: this.failed_messages.length,
@ -109,7 +109,7 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
/**
* @private
*/
_render: function() {
_render: function () {
if (this.failed_messages.length) {
this.$el.html(
QWeb.render(
@ -128,7 +128,7 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
* @private
* @param {Object} record
*/
_reset: function(record) {
_reset: function (record) {
this._super.apply(this, arguments);
this.failed_messages = this.record.specialData[this.name] || [];
this.res_id = record.res_id;
@ -140,7 +140,7 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
* @private
* @param {Array} fieldsToReload
*/
_reload: function(fieldsToReload) {
_reload: function (fieldsToReload) {
this.trigger_up("reload_mail_fields", fieldsToReload);
},
@ -151,7 +151,7 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
* @param {Int} id
* @returns {Promise}
*/
_markFailedMessageReviewed: function(id) {
_markFailedMessageReviewed: function (id) {
return this._rpc({
model: "mail.message",
method: "set_need_action_done",
@ -169,9 +169,9 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
* @private
* @param {Array} notifs
*/
_onNotification: function(notifs) {
_onNotification: function (notifs) {
var self = this;
_.each(notifs, function(notif) {
_.each(notifs, function (notif) {
var model = notif[0][1];
if (model === "res.partner") {
var data = notif[1];
@ -190,7 +190,7 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
* @private
* @param {Event} event
*/
_onRetryFailedMessage: function(event) {
_onRetryFailedMessage: function (event) {
event.preventDefault();
var messageID = $(event.currentTarget).data("message-id");
this.do_action("mail.mail_resend_message_action", {
@ -206,7 +206,7 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
* @private
* @param {Event} event
*/
_onMarkFailedMessageReviewed: function(event) {
_onMarkFailedMessageReviewed: function (event) {
event.preventDefault();
var messageID = $(event.currentTarget).data("message-id");
this._markFailedMessageReviewed(messageID).then(
@ -225,7 +225,7 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
*
* @override
*/
init: function() {
init: function () {
this._super.apply(this, arguments);
var fieldsInfo = this.fieldsInfo[this.viewType];
for (var fieldName in fieldsInfo) {
@ -254,7 +254,7 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
*
* @override
*/
init: function(parent, record, mailFields, options) {
init: function (parent, record, mailFields, options) {
this._super.apply(this, arguments);
// Initialize mail_failed_message widget
if (mailFields.mail_failed_message) {
@ -273,9 +273,9 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
* @private
* @returns {Promise}
*/
_render: function() {
_render: function () {
var self = this;
return this._super.apply(this, arguments).then(function() {
return this._super.apply(this, arguments).then(function () {
if (self.fields.failed_message) {
self.fields.failed_message.$el.insertBefore(
self.$el.find(".o_mail_thread")
@ -289,7 +289,7 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
*
* @override
*/
_onReloadMailFields: function(event) {
_onReloadMailFields: function (event) {
if (this.fields.failed_message && event.data.failed_message) {
this.trigger_up("reload", {
fieldNames: [this.fields.failed_message.name],
@ -309,7 +309,7 @@ odoo.define("mail_tracking.FailedMessageThread", function(require) {
*
* @override
*/
init: function() {
init: function () {
this._super.apply(this, arguments);
this._enabledOptions.displayRetryButton = true;
this._enabledOptions.displayReviewedButton = true;

View File

@ -2,7 +2,7 @@
Copyright 2018 David Vidal - <david.vidal@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). */
odoo.define("mail_tracking.partner_tracking", function(require) {
odoo.define("mail_tracking.partner_tracking", function (require) {
"use strict";
var core = require("web.core");
@ -19,7 +19,7 @@ odoo.define("mail_tracking.partner_tracking", function(require) {
*
* @returns {Boolean}
*/
hasPartnerTrackings: function() {
hasPartnerTrackings: function () {
return false;
},
@ -28,13 +28,13 @@ odoo.define("mail_tracking.partner_tracking", function(require) {
*
* @returns {Boolean}
*/
hasEmailCc: function() {
hasEmailCc: function () {
return false;
},
});
Message.include({
init: function(parent, data) {
init: function (parent, data) {
this._super.apply(this, arguments);
this._partnerTrackings = data.partner_trackings || [];
this._emailCc = data.email_cc || [];
@ -47,7 +47,7 @@ odoo.define("mail_tracking.partner_tracking", function(require) {
* @override
* @returns {Boolean}
*/
hasPartnerTrackings: function() {
hasPartnerTrackings: function () {
return _.some(this._partnerTrackings);
},
@ -56,7 +56,7 @@ odoo.define("mail_tracking.partner_tracking", function(require) {
*
* @returns {Boolean}
*/
hasEmailCc: function() {
hasEmailCc: function () {
return _.some(this._emailCc);
},
@ -67,7 +67,7 @@ odoo.define("mail_tracking.partner_tracking", function(require) {
* @override
* @returns {Object[]}
*/
getPartnerTrackings: function() {
getPartnerTrackings: function () {
if (!this.hasPartnerTrackings()) {
return [];
}
@ -80,7 +80,7 @@ odoo.define("mail_tracking.partner_tracking", function(require) {
*
* @returns {Array}
*/
getEmailCc: function() {
getEmailCc: function () {
if (!this.hasEmailCc()) {
return [];
}
@ -94,16 +94,16 @@ odoo.define("mail_tracking.partner_tracking", function(require) {
* @param {String} email
* @returns {Boolean}
*/
isEmailCc: function(email) {
isEmailCc: function (email) {
if (!this.hasEmailCc()) {
return false;
}
return _.some(this._emailCc, function(item) {
return _.some(this._emailCc, function (item) {
return item[0] === email;
});
},
toggleTrackingStatus: function() {
toggleTrackingStatus: function () {
return this._rpc({
model: "mail.message",
method: "toggle_tracking_status",
@ -117,7 +117,7 @@ odoo.define("mail_tracking.partner_tracking", function(require) {
"click .o_mail_action_tracking_partner": "on_tracking_partner_click",
"click .o_mail_action_tracking_status": "on_tracking_status_click",
}),
on_tracking_partner_click: function(event) {
on_tracking_partner_click: function (event) {
var partner_id = this.$el.find(event.currentTarget).data("partner");
var state = {
model: "res.partner",
@ -137,7 +137,7 @@ odoo.define("mail_tracking.partner_tracking", function(require) {
};
this.do_action(action);
},
on_tracking_status_click: function(event) {
on_tracking_status_click: function (event) {
var tracking_email_id = $(event.currentTarget).data("tracking");
var state = {
model: "mail.tracking.email",
@ -157,9 +157,9 @@ odoo.define("mail_tracking.partner_tracking", function(require) {
};
this.do_action(action);
},
init: function() {
init: function () {
this._super.apply(this, arguments);
this.action_manager = this.findAncestor(function(ancestor) {
this.action_manager = this.findAncestor(function (ancestor) {
return ancestor instanceof ActionManager;
});
},