From dd63684d632950c856ae6df7fe57e42bfeabcf88 Mon Sep 17 00:00:00 2001
From: payen000
Date: Mon, 4 Sep 2023 13:28:09 -0700
Subject: [PATCH] [MIG] mail_tracking: migration to 16.0
---
mail_tracking/__manifest__.py | 22 +--
mail_tracking/controllers/discuss.py | 14 +-
mail_tracking/demo/demo.xml | 28 ++-
mail_tracking/models/mail_thread.py | 8 +-
.../static/src/components/discuss.xml | 183 ++++++++++++++++++
.../message_failed_box.esm.js} | 10 +-
.../message_failed_box.xml} | 44 +++--
.../static/src/css/failed_message.scss | 4 +-
.../static/src/js/discuss/discuss.esm.js | 157 ---------------
.../src/js/failed_message/thread.esm.js | 58 ------
.../static/src/js/mail_tracking.esm.js | 51 -----
mail_tracking/static/src/js/message.esm.js | 23 +--
.../static/src/js/{ => models}/chatter.esm.js | 29 ++-
.../discuss_sidebar_mailbox_view.esm.js | 22 +++
.../static/src/js/models/discuss_view.esm.js | 14 ++
.../static/src/js/models/mailbox.esm.js | 61 ++++++
.../static/src/js/models/message.esm.js | 54 ++++++
.../src/js/models/message_failed.esm.js | 48 +++++
.../static/src/js/models/messaging.esm.js | 14 ++
.../js/models/messaging_initializer.esm.js | 78 ++++++++
.../static/src/js/models/thread.esm.js | 82 ++++----
.../static/src/xml/failed_message/common.xml | 23 ---
.../static/src/xml/failed_message/discuss.xml | 57 ------
.../static/src/xml/mail_tracking.xml | 110 -----------
mail_tracking/tests/test_mail_tracking.py | 17 +-
25 files changed, 602 insertions(+), 609 deletions(-)
create mode 100644 mail_tracking/static/src/components/discuss.xml
rename mail_tracking/static/src/{js/failed_message/mail_failed_box.esm.js => components/message_failed_box.esm.js} (89%)
rename mail_tracking/static/src/{xml/failed_message/thread.xml => components/message_failed_box.xml} (80%)
delete mode 100644 mail_tracking/static/src/js/discuss/discuss.esm.js
delete mode 100644 mail_tracking/static/src/js/failed_message/thread.esm.js
delete mode 100644 mail_tracking/static/src/js/mail_tracking.esm.js
rename mail_tracking/static/src/js/{ => models}/chatter.esm.js (53%)
create mode 100644 mail_tracking/static/src/js/models/discuss_sidebar_mailbox_view.esm.js
create mode 100644 mail_tracking/static/src/js/models/discuss_view.esm.js
create mode 100644 mail_tracking/static/src/js/models/mailbox.esm.js
create mode 100644 mail_tracking/static/src/js/models/message.esm.js
create mode 100644 mail_tracking/static/src/js/models/message_failed.esm.js
create mode 100644 mail_tracking/static/src/js/models/messaging.esm.js
create mode 100644 mail_tracking/static/src/js/models/messaging_initializer.esm.js
delete mode 100644 mail_tracking/static/src/xml/failed_message/common.xml
delete mode 100644 mail_tracking/static/src/xml/failed_message/discuss.xml
delete mode 100644 mail_tracking/static/src/xml/mail_tracking.xml
diff --git a/mail_tracking/__manifest__.py b/mail_tracking/__manifest__.py
index 5e9bb436ea..0346e30af8 100644
--- a/mail_tracking/__manifest__.py
+++ b/mail_tracking/__manifest__.py
@@ -7,7 +7,7 @@
{
"name": "Email tracking",
"summary": "Email tracking system for all mails sent",
- "version": "15.0.3.1.0",
+ "version": "16.0.1.0.0",
"category": "Social Network",
"website": "https://github.com/OCA/social",
"author": ("Tecnativa, " "Odoo Community Association (OCA)"),
@@ -27,21 +27,11 @@
],
"assets": {
"web.assets_backend": [
- "mail_tracking/static/src/css/mail_tracking.scss",
- "mail_tracking/static/src/css/failed_message.scss",
- "mail_tracking/static/src/js/mail_tracking.esm.js",
- "mail_tracking/static/src/js/message.esm.js",
- "mail_tracking/static/src/js/failed_message/mail_failed_box.esm.js",
- "mail_tracking/static/src/js/failed_message/thread.esm.js",
- "mail_tracking/static/src/js/models/thread.esm.js",
- "mail_tracking/static/src/js/chatter.esm.js",
- "mail_tracking/static/src/js/discuss/discuss.esm.js",
- ],
- "web.assets_qweb": [
- "mail_tracking/static/src/xml/mail_tracking.xml",
- "mail_tracking/static/src/xml/failed_message/common.xml",
- "mail_tracking/static/src/xml/failed_message/thread.xml",
- "mail_tracking/static/src/xml/failed_message/discuss.xml",
+ "mail_tracking/static/src/css/*.scss",
+ "mail_tracking/static/src/js/models/*.esm.js",
+ "mail_tracking/static/src/js/*.esm.js",
+ "mail_tracking/static/src/components/*.xml",
+ "mail_tracking/static/src/components/*.esm.js",
],
},
"demo": ["demo/demo.xml"],
diff --git a/mail_tracking/controllers/discuss.py b/mail_tracking/controllers/discuss.py
index 8a5652d24b..8d73f545c5 100644
--- a/mail_tracking/controllers/discuss.py
+++ b/mail_tracking/controllers/discuss.py
@@ -16,9 +16,13 @@ def mail_init_messaging(self):
@http.route("/mail/failed/messages", methods=["POST"], type="json", auth="user")
def discuss_failed_messages(self, max_id=None, min_id=None, limit=30, **kwargs):
- return http.request.env["mail.message"]._message_fetch(
- domain=[("is_failed_message", "=", True)],
- max_id=max_id,
- min_id=min_id,
- limit=limit,
+ return (
+ http.request.env["mail.message"]
+ ._message_fetch(
+ domain=[("is_failed_message", "=", True)],
+ max_id=max_id,
+ min_id=min_id,
+ limit=limit,
+ )
+ .message_format()
)
diff --git a/mail_tracking/demo/demo.xml b/mail_tracking/demo/demo.xml
index ed47000687..4442a5da01 100644
--- a/mail_tracking/demo/demo.xml
+++ b/mail_tracking/demo/demo.xml
@@ -13,10 +13,13 @@
This is a message with CC
]]>
wood.corner26@example.com
-
+
Message with CC
@@ -41,10 +44,13 @@
This is a failed message]]>
wood.corner26@example.com
-
+
Failed Message
@@ -69,10 +75,13 @@
This is another failed message]]>
jackson.group82@example.com
-
+
Failed Message
@@ -97,10 +106,13 @@
This is another failed message]]>
admin@example.com
-
+
Failed Message
diff --git a/mail_tracking/models/mail_thread.py b/mail_tracking/models/mail_thread.py
index b36de8452c..ccd8b93e7e 100644
--- a/mail_tracking/models/mail_thread.py
+++ b/mail_tracking/models/mail_thread.py
@@ -89,17 +89,13 @@ def _add_extra_recipients_suggestions(self, suggestions, field_mail, reason):
)
@api.model
- def _fields_view_get(
- self, view_id=None, view_type="form", toolbar=False, submenu=False
- ):
+ def get_view(self, view_id=None, view_type="form", **options):
"""Add filters for failed messages.
These filters will show up on any form or search views of any
model inheriting from ``mail.thread``.
"""
- res = super()._fields_view_get(
- view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
- )
+ res = super().get_view(view_id, view_type, **options)
if view_type != "search":
return res
doc = etree.XML(res["arch"])
diff --git a/mail_tracking/static/src/components/discuss.xml b/mail_tracking/static/src/components/discuss.xml
new file mode 100644
index 0000000000..24c65c5ed2
--- /dev/null
+++ b/mail_tracking/static/src/components/discuss.xml
@@ -0,0 +1,183 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ No failed messages
+
+ Failed messages will be appeared here.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Set as Reviewed
+
+
+
+ Retry
+
+
+
+
+
+
+
+
+
+
+ To:
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/mail_tracking/static/src/js/failed_message/mail_failed_box.esm.js b/mail_tracking/static/src/components/message_failed_box.esm.js
similarity index 89%
rename from mail_tracking/static/src/js/failed_message/mail_failed_box.esm.js
rename to mail_tracking/static/src/components/message_failed_box.esm.js
index db1a5c3c62..5e80b6c4a4 100644
--- a/mail_tracking/static/src/js/failed_message/mail_failed_box.esm.js
+++ b/mail_tracking/static/src/components/message_failed_box.esm.js
@@ -42,17 +42,15 @@ export class MessageFailedBox extends Component {
}
/**
- * @returns {Chatter}
+ * @returns {MessageFailedBoxView}
*/
- get chatter() {
- return this.messaging.models["mail.chatter"].get(this.props.chatterLocalId);
+ get messageFailedBoxView() {
+ return this.props.record;
}
}
Object.assign(MessageFailedBox, {
- props: {
- chatterLocalId: String,
- },
+ props: {record: Object},
template: "mail_tracking.MessageFailedBox",
});
diff --git a/mail_tracking/static/src/xml/failed_message/thread.xml b/mail_tracking/static/src/components/message_failed_box.xml
similarity index 80%
rename from mail_tracking/static/src/xml/failed_message/thread.xml
rename to mail_tracking/static/src/components/message_failed_box.xml
index 0251bf5d7f..b3e6a51e05 100644
--- a/mail_tracking/static/src/xml/failed_message/thread.xml
+++ b/mail_tracking/static/src/components/message_failed_box.xml
@@ -1,26 +1,29 @@
+
-
-
+
+
Failed messages
-
+
-
+
-
+
@@ -28,11 +31,11 @@
@@ -43,11 +46,11 @@
-
@@ -77,7 +80,7 @@
t-on-click="_onRetryFailedMessage"
t-att-data-message-id="messagefailed.id"
>
- Retry
+ Retry
@@ -86,6 +89,7 @@
-
@@ -108,20 +112,22 @@
-
-
+
+
+
-
+
+
diff --git a/mail_tracking/static/src/css/failed_message.scss b/mail_tracking/static/src/css/failed_message.scss
index 7bd1be3540..23e1772473 100644
--- a/mail_tracking/static/src/css/failed_message.scss
+++ b/mail_tracking/static/src/css/failed_message.scss
@@ -116,8 +116,8 @@
margin-bottom: 0px;
&.o_mail_not_discussion {
- background-color: rgba(gray("300"), 0.5);
- border-bottom: 1px solid gray("400");
+ background-color: rgba(map-get($grays, "300"), 0.5);
+ border-bottom: 1px solid map-get($grays, "400");
}
.o_thread_message_sidebar {
diff --git a/mail_tracking/static/src/js/discuss/discuss.esm.js b/mail_tracking/static/src/js/discuss/discuss.esm.js
deleted file mode 100644
index dba8507781..0000000000
--- a/mail_tracking/static/src/js/discuss/discuss.esm.js
+++ /dev/null
@@ -1,157 +0,0 @@
-/** @odoo-module **/
-
-import {attr, many2one, one2one} from "@mail/model/model_field";
-import {insertAndReplace, replace} from "@mail/model/model_field_command";
-import {
- registerClassPatchModel,
- registerFieldPatchModel,
- registerInstancePatchModel,
-} from "@mail/model/model_core";
-
-registerInstancePatchModel(
- "mail.messaging_initializer",
- "mail/static/src/models/messaging_initializer/messaging_initializer.js",
- {
- async start() {
- this.messaging.update({
- failedmsg: insertAndReplace({
- id: "failedmsg",
- isServerPinned: true,
- model: "mail.box",
- name: this.env._t("Failed"),
- }),
- });
- return this._super(...arguments);
- },
- async _init({
- channels,
- companyName,
- current_partner,
- currentGuest,
- current_user_id,
- current_user_settings,
- mail_failures = [],
- menu_id,
- needaction_inbox_counter = 0,
- partner_root,
- public_partners,
- shortcodes = [],
- starred_counter = 0,
- failed_counter = 0,
- }) {
- const discuss = this.messaging.discuss;
- // Partners first because the rest of the code relies on them
- this._initPartners({
- currentGuest,
- current_partner,
- current_user_id,
- partner_root,
- public_partners,
- });
- // Mailboxes after partners and before other initializers that might
- // manipulate threads or messages
- this._initMailboxes({
- needaction_inbox_counter,
- starred_counter,
- failed_counter,
- });
- // Init mail user settings
- if (current_user_settings) {
- this._initResUsersSettings(current_user_settings);
- } else {
- this.messaging.update({
- userSetting: insertAndReplace({
- // Fake id for guest
- id: -1,
- }),
- });
- }
- // Various suggestions in no particular order
- this._initCannedResponses(shortcodes);
- // FIXME: guests should have (at least some) commands available
- if (!this.messaging.isCurrentUserGuest) {
- this._initCommands();
- }
- // Channels when the rest of messaging is ready
- await this.async(() => this._initChannels(channels));
- // Failures after channels
- this._initMailFailures(mail_failures);
- discuss.update({menu_id});
- // Company related data
- this.messaging.update({companyName});
- },
-
- _initMailboxes({needaction_inbox_counter, starred_counter, failed_counter}) {
- this.messaging.inbox.update({counter: needaction_inbox_counter});
- this.messaging.starred.update({counter: starred_counter});
- this.messaging.failedmsg.update({counter: failed_counter});
- },
- }
-);
-
-registerFieldPatchModel(
- "mail.messaging",
- "mail/static/src/models/messaging/messaging.js",
- {
- failedmsg: one2one("mail.thread"),
- }
-);
-
-registerInstancePatchModel(
- "mail.thread_cache",
- "mail/static/src/models/thread_cache/thread_cache.js",
- {
- _extendMessageDomain(domain) {
- const thread = this.thread;
- if (thread === this.env.messaging.failedmsg) {
- return domain.concat([["is_failed_message", "=", true]]);
- }
- return this._super(...arguments);
- },
- }
-);
-
-registerFieldPatchModel("mail.message", "mail/static/src/models/message/message.js", {
- messagingFailedmsg: many2one("mail.thread", {
- related: "messaging.failedmsg",
- }),
- isFailed: attr({
- default: false,
- }),
-});
-
-registerClassPatchModel("mail.message", "mail/static/src/models/message/message.js", {
- convertData(data) {
- const data2 = this._super(data);
- if ("is_failed_message" in data) {
- data2.isFailed = data.is_failed_message;
- }
- return data2;
- },
-});
-
-registerInstancePatchModel(
- "mail.message",
- "mail/static/src/models/message/message.js",
- {
- _computeThreads() {
- const threads = [];
- if (this.isHistory && this.messaging.history) {
- threads.push(this.messaging.history);
- }
- if (this.isNeedaction && this.messaging.inbox) {
- threads.push(this.messaging.inbox);
- }
- if (this.isStarred && this.messaging.starred) {
- threads.push(this.messaging.starred);
- }
- if (this.isFailed && this.messaging.failedmsg) {
- threads.push(this.messaging.failedmsg);
- }
- if (this.originThread) {
- threads.push(this.originThread);
- }
- return replace(threads);
- },
- }
-);
diff --git a/mail_tracking/static/src/js/failed_message/thread.esm.js b/mail_tracking/static/src/js/failed_message/thread.esm.js
deleted file mode 100644
index 8e47f58c0c..0000000000
--- a/mail_tracking/static/src/js/failed_message/thread.esm.js
+++ /dev/null
@@ -1,58 +0,0 @@
-/** @odoo-module **/
-
-import {
- registerFieldPatchModel,
- registerInstancePatchModel,
-} from "@mail/model/model_core";
-import {one2many} from "@mail/model/model_field";
-
-registerInstancePatchModel(
- "mail.thread",
- "mail_tracking/static/src/js/failed_message/thread.esm.js",
- {
- async refreshMessagefailed() {
- var id = this.__values.id;
- var model = this.__values.model;
- const messagefailedData = await this.async(() =>
- this.env.services.rpc(
- {
- model: "mail.message",
- method: "get_failed_messsage_info",
- args: [id, model],
- },
- {
- shadow: true,
- }
- )
- );
- const messagefailed = this.messaging.models["mail.message.failed"].insert(
- messagefailedData.map((messageData) =>
- this.messaging.models["mail.message.failed"].convertData(
- messageData
- )
- )
- );
- this.update({
- messagefailed: [["replace", messagefailed]],
- });
- },
-
- _computeFetchMessagesUrl() {
- switch (this) {
- case this.messaging.failedmsg:
- return "/mail/failed/messages";
- }
- return this._super();
- },
- }
-);
-
-registerFieldPatchModel(
- "mail.thread",
- "mail_tracking/static/src/js/failed_message/thread.esm.js",
- {
- messagefailed: one2many("mail.message.failed", {
- inverse: "thread",
- }),
- }
-);
diff --git a/mail_tracking/static/src/js/mail_tracking.esm.js b/mail_tracking/static/src/js/mail_tracking.esm.js
deleted file mode 100644
index 23c8587597..0000000000
--- a/mail_tracking/static/src/js/mail_tracking.esm.js
+++ /dev/null
@@ -1,51 +0,0 @@
-/** @odoo-module **/
-
-import {
- registerClassPatchModel,
- registerFieldPatchModel,
- registerInstancePatchModel,
-} from "@mail/model/model_core";
-import {attr} from "@mail/model/model_field";
-
-registerClassPatchModel(
- "mail.message",
- "mail_tracking/static/src/js/mail_tracking.esm.js",
- {
- convertData(data) {
- const data2 = this._super(data);
- if ("partner_trackings" in data) {
- data2.partner_trackings = data.partner_trackings;
- }
- return data2;
- },
- }
-);
-
-registerFieldPatchModel(
- "mail.message",
- "mail_tracking/static/src/js/mail_tracking.esm.js",
- {
- partner_trackings: attr(),
- }
-);
-
-registerInstancePatchModel(
- "mail.model",
- "mail_tracking/static/src/js/mail_tracking.esm.js",
- {
- hasPartnerTrackings() {
- return _.some(this.__values.partner_trackings);
- },
-
- hasEmailCc() {
- return _.some(this._emailCc);
- },
-
- getPartnerTrackings: function () {
- if (!this.hasPartnerTrackings()) {
- return [];
- }
- return this.__values.partner_trackings;
- },
- }
-);
diff --git a/mail_tracking/static/src/js/message.esm.js b/mail_tracking/static/src/js/message.esm.js
index 413d3d46c7..2b9b91546c 100644
--- a/mail_tracking/static/src/js/message.esm.js
+++ b/mail_tracking/static/src/js/message.esm.js
@@ -24,32 +24,29 @@ patch(Message.prototype, "mail_tracking/static/src/js/message.esm.js", {
},
// For discuss
- _onMarkFailedMessageReviewed(event) {
+ async _onMarkFailedMessageReviewed(event) {
event.preventDefault();
var messageID = $(event.currentTarget).data("message-id");
- this._markFailedMessageReviewed(messageID);
+ await this._markFailedMessageReviewed(messageID);
window.location.reload();
},
_onRetryFailedMessage(event) {
event.preventDefault();
var messageID = $(event.currentTarget).data("message-id");
- this.env.bus.trigger("do-action", {
- action: "mail.mail_resend_message_action",
- options: {
- additional_context: {
- mail_message_to_resend: messageID,
- },
- on_close: () => {
- window.location.reload();
- },
+ this.env.services.action.doAction("mail.mail_resend_message_action", {
+ additionalContext: {
+ mail_message_to_resend: messageID,
+ },
+ onClose: () => {
+ window.location.reload();
},
});
},
_markFailedMessageReviewed(id) {
- return this.env.services.rpc({
+ return this.messaging.rpc({
model: "mail.message",
method: "set_need_action_done",
- args: [[id]],
+ args: [id],
});
},
});
diff --git a/mail_tracking/static/src/js/chatter.esm.js b/mail_tracking/static/src/js/models/chatter.esm.js
similarity index 53%
rename from mail_tracking/static/src/js/chatter.esm.js
rename to mail_tracking/static/src/js/models/chatter.esm.js
index edb52d316c..4056a5a313 100644
--- a/mail_tracking/static/src/js/chatter.esm.js
+++ b/mail_tracking/static/src/js/models/chatter.esm.js
@@ -1,17 +1,14 @@
/** @odoo-module **/
-import {
- registerFieldPatchModel,
- registerInstancePatchModel,
-} from "@mail/model/model_core";
+
import {attr} from "@mail/model/model_field";
+import {registerPatch} from "@mail/model/model_core";
-registerInstancePatchModel(
- "mail.chatter",
- "mail/static/src/models/chatter/chatter.esm.js",
- {
+registerPatch({
+ name: "Chatter",
+ recordMethods: {
async refresh() {
this._super(...arguments);
- this.thread.refreshMessagefailed();
+ if (this.thread) this.thread.refreshMessagefailed();
},
toggleMessageFailedBoxVisibility() {
this.update({
@@ -20,16 +17,12 @@ registerInstancePatchModel(
},
_onThreadIdOrThreadModelChanged() {
this._super(...arguments);
- this.thread.refreshMessagefailed();
+ if (this.thread) this.thread.refreshMessagefailed();
},
- }
-);
-registerFieldPatchModel(
- "mail.chatter",
- "mail/static/src/models/chatter/chatter.esm.js",
- {
+ },
+ fields: {
isMessageFailedBoxVisible: attr({
default: true,
}),
- }
-);
+ },
+});
diff --git a/mail_tracking/static/src/js/models/discuss_sidebar_mailbox_view.esm.js b/mail_tracking/static/src/js/models/discuss_sidebar_mailbox_view.esm.js
new file mode 100644
index 0000000000..57f9e21b4f
--- /dev/null
+++ b/mail_tracking/static/src/js/models/discuss_sidebar_mailbox_view.esm.js
@@ -0,0 +1,22 @@
+/** @odoo-module **/
+
+import {one} from "@mail/model/model_field";
+import {registerPatch} from "@mail/model/model_core";
+
+registerPatch({
+ name: "DiscussSidebarMailboxView",
+ fields: {
+ discussViewOwnerAsFailedMessage: one("DiscussView", {
+ identifying: true,
+ inverse: "failedMessageView",
+ }),
+ mailbox: {
+ compute() {
+ if (this.discussViewOwnerAsFailedMessage) {
+ return this.messaging.failedmsg;
+ }
+ return this._super();
+ },
+ },
+ },
+});
diff --git a/mail_tracking/static/src/js/models/discuss_view.esm.js b/mail_tracking/static/src/js/models/discuss_view.esm.js
new file mode 100644
index 0000000000..e351270a25
--- /dev/null
+++ b/mail_tracking/static/src/js/models/discuss_view.esm.js
@@ -0,0 +1,14 @@
+/** @odoo-module **/
+
+import {one} from "@mail/model/model_field";
+import {registerPatch} from "@mail/model/model_core";
+
+registerPatch({
+ name: "DiscussView",
+ fields: {
+ failedMessageView: one("DiscussSidebarMailboxView", {
+ default: {},
+ inverse: "discussViewOwnerAsFailedMessage",
+ }),
+ },
+});
diff --git a/mail_tracking/static/src/js/models/mailbox.esm.js b/mail_tracking/static/src/js/models/mailbox.esm.js
new file mode 100644
index 0000000000..132f357e70
--- /dev/null
+++ b/mail_tracking/static/src/js/models/mailbox.esm.js
@@ -0,0 +1,61 @@
+/** @odoo-module **/
+
+import {many, one} from "@mail/model/model_field";
+import {registerPatch} from "@mail/model/model_core";
+
+registerPatch({
+ name: "Mailbox",
+ fields: {
+ messagefailed: many("MessageFailed", {
+ inverse: "threads",
+ }),
+ fetchMessagesUrl: {
+ compute() {
+ switch (this) {
+ case this.messaging.failedmsg:
+ return "/mail/failed/messages";
+ }
+ return this._super();
+ },
+ },
+ messagingAsFailed: one("Messaging", {
+ identifying: true,
+ inverse: "failedmsg",
+ }),
+ name: {
+ compute() {
+ switch (this) {
+ case this.messaging.failedmsg:
+ return this.env._t("Failed");
+ }
+ return this._super();
+ },
+ },
+ sequence: {
+ compute() {
+ switch (this) {
+ case this.messaging.failedmsg:
+ return 3;
+ }
+ return this._super();
+ },
+ },
+ thread: {
+ compute() {
+ const threadId = (() => {
+ switch (this) {
+ case this.messaging.failedmsg:
+ return "failedmsg";
+ }
+ })();
+ if (!threadId) {
+ return this._super();
+ }
+ return {
+ id: threadId,
+ model: "mail.box",
+ };
+ },
+ },
+ },
+});
diff --git a/mail_tracking/static/src/js/models/message.esm.js b/mail_tracking/static/src/js/models/message.esm.js
new file mode 100644
index 0000000000..4f46710341
--- /dev/null
+++ b/mail_tracking/static/src/js/models/message.esm.js
@@ -0,0 +1,54 @@
+/** @odoo-module **/
+
+import {attr, one} from "@mail/model/model_field";
+import {registerPatch} from "@mail/model/model_core";
+
+registerPatch({
+ name: "Message",
+ modelMethods: {
+ convertData(data) {
+ const data2 = this._super(data);
+ if ("partner_trackings" in data) {
+ data2.partner_trackings = data.partner_trackings;
+ }
+ if ("is_failed_message" in data) {
+ data2.isFailed = data.is_failed_message;
+ }
+ return data2;
+ },
+ },
+ recordMethods: {
+ hasPartnerTrackings() {
+ return _.some(this.__values.get("partner_trackings"));
+ },
+
+ hasEmailCc() {
+ return _.some(this._emailCc);
+ },
+
+ getPartnerTrackings: function () {
+ if (!this.hasPartnerTrackings()) {
+ return [];
+ }
+ return this.__values.get("partner_trackings");
+ },
+ },
+ fields: {
+ partner_trackings: attr(),
+ threads: {
+ compute() {
+ const threads = this._super();
+ if (this.isFailed && this.messaging.failedmsg) {
+ threads.push(this.messaging.failedmsg.thread);
+ }
+ return threads;
+ },
+ },
+ messagingFailedmsg: one("Mailbox", {
+ related: "messaging.failedmsg",
+ }),
+ isFailed: attr({
+ default: false,
+ }),
+ },
+});
diff --git a/mail_tracking/static/src/js/models/message_failed.esm.js b/mail_tracking/static/src/js/models/message_failed.esm.js
new file mode 100644
index 0000000000..705c83dbcb
--- /dev/null
+++ b/mail_tracking/static/src/js/models/message_failed.esm.js
@@ -0,0 +1,48 @@
+/** @odoo-module **/
+
+import {attr, one} from "@mail/model/model_field";
+import {registerModel} from "@mail/model/model_core";
+
+registerModel({
+ name: "MessageFailed",
+ modelMethods: {
+ convertData(data) {
+ const data2 = {};
+ if ("author" in data) {
+ if (data.author) {
+ data2.author = data.author[1];
+ data2.author_id = data.author[0];
+ } else {
+ data2.author = [["unlink-all"]];
+ }
+ }
+ if ("body" in data) {
+ data2.body = data.body;
+ }
+ if ("date" in data) {
+ data2.date = data.date;
+ }
+ if ("failed_recipients" in data) {
+ data2.failed_recipients = data.failed_recipients;
+ }
+ if ("id" in data) {
+ data2.id = data.id;
+ }
+ return data2;
+ },
+ },
+ fields: {
+ threads: one("Mailbox", {
+ inverse: "messagefailed",
+ }),
+ body: attr(),
+ author: attr(),
+ author_id: attr(),
+ date: attr(),
+ failed_recipients: attr(),
+ id: attr({
+ readonly: true,
+ required: true,
+ }),
+ },
+});
diff --git a/mail_tracking/static/src/js/models/messaging.esm.js b/mail_tracking/static/src/js/models/messaging.esm.js
new file mode 100644
index 0000000000..714d4ab213
--- /dev/null
+++ b/mail_tracking/static/src/js/models/messaging.esm.js
@@ -0,0 +1,14 @@
+/** @odoo-module **/
+
+import {one} from "@mail/model/model_field";
+import {registerPatch} from "@mail/model/model_core";
+
+registerPatch({
+ name: "Messaging",
+ fields: {
+ failedmsg: one("Mailbox", {
+ default: {},
+ inverse: "messagingAsFailed",
+ }),
+ },
+});
diff --git a/mail_tracking/static/src/js/models/messaging_initializer.esm.js b/mail_tracking/static/src/js/models/messaging_initializer.esm.js
new file mode 100644
index 0000000000..91edd74b5c
--- /dev/null
+++ b/mail_tracking/static/src/js/models/messaging_initializer.esm.js
@@ -0,0 +1,78 @@
+/** @odoo-module **/
+
+import {registerPatch} from "@mail/model/model_core";
+
+registerPatch({
+ name: "MessagingInitializer",
+ recordMethods: {
+ async _init({
+ channels,
+ companyName,
+ current_partner,
+ currentGuest,
+ current_user_id,
+ current_user_settings,
+ hasLinkPreviewFeature,
+ internalUserGroupId,
+ mail_failures = [],
+ menu_id,
+ needaction_inbox_counter = 0,
+ partner_root,
+ public_partners,
+ shortcodes = [],
+ starred_counter = 0,
+ failed_counter = 0,
+ }) {
+ const discuss = this.messaging.discuss;
+ // Partners first because the rest of the code relies on them
+ this._initPartners({
+ currentGuest,
+ current_partner,
+ current_user_id,
+ partner_root,
+ public_partners,
+ });
+ // Mailboxes after partners and before other initializers that might
+ // manipulate threads or messages
+ this._initMailboxes({
+ needaction_inbox_counter,
+ starred_counter,
+ failed_counter,
+ });
+ // Init mail user settings
+ if (current_user_settings) {
+ this.messaging.models["res.users.settings"].insert(
+ current_user_settings
+ );
+ }
+ // Various suggestions in no particular order
+ this._initCannedResponses(shortcodes);
+ // FIXME: guests should have (at least some) commands available
+ if (!this.messaging.isCurrentUserGuest) {
+ this._initCommands();
+ }
+ // Channels when the rest of messaging is ready
+ if (channels) {
+ await this._initChannels(channels);
+ }
+ if (!this.exists()) {
+ return;
+ }
+ // Failures after channels
+ this._initMailFailures(mail_failures);
+ discuss.update({menu_id});
+ // Company related data
+ this.messaging.update({
+ companyName,
+ hasLinkPreviewFeature,
+ internalUserGroupId,
+ });
+ },
+
+ _initMailboxes({needaction_inbox_counter, starred_counter, failed_counter}) {
+ this.messaging.inbox.update({counter: needaction_inbox_counter});
+ this.messaging.starred.update({counter: starred_counter});
+ this.messaging.failedmsg.update({counter: failed_counter});
+ },
+ },
+});
diff --git a/mail_tracking/static/src/js/models/thread.esm.js b/mail_tracking/static/src/js/models/thread.esm.js
index 6584ab0cb2..3ab7032543 100644
--- a/mail_tracking/static/src/js/models/thread.esm.js
+++ b/mail_tracking/static/src/js/models/thread.esm.js
@@ -1,53 +1,37 @@
/** @odoo-module **/
-import {attr, many2one} from "@mail/model/model_field";
-import {registerNewModel} from "@mail/model/model_core";
-function factory(dependencies) {
- class MessageFailed extends dependencies["mail.model"] {
- static convertData(data) {
- const data2 = {};
- if ("author" in data) {
- if (data.author) {
- data2.author = data.author[1];
- data2.author_id = data.author[0];
- } else {
- data2.author = [["unlink-all"]];
- }
- }
- if ("body" in data) {
- data2.body = data.body;
- }
- if ("date" in data) {
- data2.date = data.date;
- }
- if ("failed_recipients" in data) {
- data2.failed_recipients = data.failed_recipients;
- }
- if ("id" in data) {
- data2.id = data.id;
- }
- return data2;
- }
- }
+import {many} from "@mail/model/model_field";
+import {registerPatch} from "@mail/model/model_core";
- MessageFailed.fields = {
- thread: many2one("mail.thread", {
- inverse: "messagefailed",
- }),
- body: attr(),
- author: attr(),
- author_id: attr(),
- date: attr(),
- failed_recipients: attr(),
- id: attr({
- readonly: true,
- required: true,
+registerPatch({
+ name: "Thread",
+ recordMethods: {
+ async refreshMessagefailed() {
+ var id = this.__values.id;
+ var model = this.__values.model;
+ const messagefailedData = await this.messaging.rpc(
+ {
+ model: "mail.message",
+ method: "get_failed_messsage_info",
+ args: [id, model],
+ },
+ {
+ shadow: true,
+ }
+ );
+ const messagefailed = this.messaging.models.MessageFailed.insert(
+ messagefailedData.map((messageData) =>
+ this.messaging.models.MessageFailed.convertData(messageData)
+ )
+ );
+ this.update({
+ messagefailed: [["replace", messagefailed]],
+ });
+ },
+ },
+ fields: {
+ messagefailed: many("MessageFailed", {
+ related: "mailbox.messagefailed",
}),
- };
-
- MessageFailed.modelName = "mail.message.failed";
- MessageFailed.identifyingFields = ["id"];
- return MessageFailed;
-}
-
-registerNewModel("mail.message.failed", factory);
+ },
+});
diff --git a/mail_tracking/static/src/xml/failed_message/common.xml b/mail_tracking/static/src/xml/failed_message/common.xml
deleted file mode 100644
index 5aeeb81708..0000000000
--- a/mail_tracking/static/src/xml/failed_message/common.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
- Set as Reviewed
-
-
- Retry
-
-
-
-
-
diff --git a/mail_tracking/static/src/xml/failed_message/discuss.xml b/mail_tracking/static/src/xml/failed_message/discuss.xml
deleted file mode 100644
index 3ed3090a57..0000000000
--- a/mail_tracking/static/src/xml/failed_message/discuss.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- No failed messages
-
- Failed messages will be appeared here.
-
-
-
-
-
-
-
-
-
-
- Set as Reviewed
-
-
-
- Retry
-
-
-
-
-
-
diff --git a/mail_tracking/static/src/xml/mail_tracking.xml b/mail_tracking/static/src/xml/mail_tracking.xml
deleted file mode 100644
index 4cdd19e983..0000000000
--- a/mail_tracking/static/src/xml/mail_tracking.xml
+++ /dev/null
@@ -1,110 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- To:
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/mail_tracking/tests/test_mail_tracking.py b/mail_tracking/tests/test_mail_tracking.py
index cb93467333..28c526f0a1 100644
--- a/mail_tracking/tests/test_mail_tracking.py
+++ b/mail_tracking/tests/test_mail_tracking.py
@@ -3,8 +3,8 @@
import base64
import time
+from unittest.mock import patch
-import mock
import psycopg2
import psycopg2.errorcodes
@@ -108,10 +108,6 @@ def test_message_post(self):
self.assertEqual(tracking_email.state, "sent")
# message_dict read by web interface
message_dict = message.message_format()[0]
- self.assertTrue(len(message_dict["partner_ids"]) > 0)
- # First partner is recipient
- partner_id = message_dict["partner_ids"][0]
- self.assertEqual(partner_id, self.recipient.id)
status = message_dict["partner_trackings"][0]
# Tracking status must be sent and
# mail tracking must be the one search before
@@ -181,7 +177,6 @@ def test_message_post_show_aliases(self):
"body": "This is another test message
",
}
)
- message._moderate_accept()
message_dict, *_ = message.message_format()
self.assertTrue(
any(
@@ -408,7 +403,7 @@ def test_mail_send(self):
mail, tracking = self.mail_send(self.recipient.email)
self.assertEqual(mail.email_to, tracking.recipient)
self.assertEqual(mail.email_from, tracking.sender)
- with mock.patch("odoo.http.db_filter") as mock_client:
+ with patch("odoo.http.db_filter") as mock_client:
mock_client.return_value = True
res = controller.mail_tracking_open(db, tracking.id, tracking.token)
self.assertEqual(image, res.response[0])
@@ -423,7 +418,7 @@ def test_mail_send(self):
def test_mail_tracking_open(self):
controller = MailTrackingController()
db = self.env.cr.dbname
- with mock.patch("odoo.http.db_filter") as mock_client:
+ with patch("odoo.http.db_filter") as mock_client:
mock_client.return_value = True
mail, tracking = self.mail_send(self.recipient.email)
# Tracking is in sent or delivered state. But no token give.
@@ -513,7 +508,7 @@ def test_concurrent_click(self):
@mute_logger("odoo.addons.mail.models.mail_mail")
def test_smtp_error(self):
- with mock.patch(mock_send_email) as mock_func:
+ with patch(mock_send_email) as mock_func:
mock_func.side_effect = Warning("Test error")
mail, tracking = self.mail_send(self.recipient.email)
self.assertEqual("error", tracking.state)
@@ -613,7 +608,7 @@ def test_recordset_email_score(self):
def test_db(self):
db = self.env.cr.dbname
controller = MailTrackingController()
- with mock.patch("odoo.http.db_filter") as mock_client:
+ with patch("odoo.http.db_filter") as mock_client:
mock_client.return_value = True
with self.assertRaises(psycopg2.OperationalError):
controller.mail_tracking_event("not_found_db")
@@ -665,7 +660,7 @@ def assert_tracking_tag_side_effect(*args, **kwargs):
msg = "data-odoo-tracking-email found"
raise AssertionError(msg)
- with mock.patch(mock_send_email) as mock_func:
+ with patch(mock_send_email) as mock_func:
mock_func.side_effect = assert_tracking_tag_side_effect
self.env["ir.config_parameter"].set_param(
"mail_tracking.tracking_img_disabled", False