Skip to content

Commit 468d3ca

Browse files
committed
[MIG] mail_tracking: Migration to 19.0
1 parent 8ab08a4 commit 468d3ca

25 files changed

+192
-279
lines changed

mail_tracking/README.rst

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Email tracking
2121
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2222
:alt: License: AGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmail-lightgray.png?logo=github
24-
:target: https://github.com/OCA/mail/tree/18.0/mail_tracking
24+
:target: https://github.com/OCA/mail/tree/19.0/mail_tracking
2525
:alt: OCA/mail
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_tracking
27+
:target: https://translation.odoo-community.org/projects/mail-19-0/mail-19-0-mail_tracking
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -113,18 +113,18 @@ records with messages in failed status and that needs an user action.
113113

114114
|image2|
115115

116-
.. |unknown| image:: https://raw.githubusercontent.com/OCA/mail/18.0/mail_tracking/static/src/img/unknown.png
117-
.. |waiting| image:: https://raw.githubusercontent.com/OCA/mail/18.0/mail_tracking/static/src/img/waiting.png
118-
.. |error| image:: https://raw.githubusercontent.com/OCA/mail/18.0/mail_tracking/static/src/img/error.png
119-
.. |sent| image:: https://raw.githubusercontent.com/OCA/mail/18.0/mail_tracking/static/src/img/sent.png
120-
.. |delivered| image:: https://raw.githubusercontent.com/OCA/mail/18.0/mail_tracking/static/src/img/delivered.png
121-
.. |opened| image:: https://raw.githubusercontent.com/OCA/mail/18.0/mail_tracking/static/src/img/opened.png
122-
.. |cc| image:: https://raw.githubusercontent.com/OCA/mail/18.0/mail_tracking/static/src/img/cc.png
123-
.. |noemail| image:: https://raw.githubusercontent.com/OCA/mail/18.0/mail_tracking/static/src/img/no_email.png
124-
.. |anonuser| image:: https://raw.githubusercontent.com/OCA/mail/18.0/mail_tracking/static/src/img/anon_user.png
125-
.. |image| image:: https://raw.githubusercontent.com/OCA/mail/18.0/mail_tracking/static/img/failed_message_discuss.png
126-
.. |image1| image:: https://raw.githubusercontent.com/OCA/mail/18.0/mail_tracking/static/img/failed_message_widget.png
127-
.. |image2| image:: https://raw.githubusercontent.com/OCA/mail/18.0/mail_tracking/static/img/failed_message_filter.png
116+
.. |unknown| image:: https://raw.githubusercontent.com/OCA/mail/19.0/mail_tracking/static/src/img/unknown.png
117+
.. |waiting| image:: https://raw.githubusercontent.com/OCA/mail/19.0/mail_tracking/static/src/img/waiting.png
118+
.. |error| image:: https://raw.githubusercontent.com/OCA/mail/19.0/mail_tracking/static/src/img/error.png
119+
.. |sent| image:: https://raw.githubusercontent.com/OCA/mail/19.0/mail_tracking/static/src/img/sent.png
120+
.. |delivered| image:: https://raw.githubusercontent.com/OCA/mail/19.0/mail_tracking/static/src/img/delivered.png
121+
.. |opened| image:: https://raw.githubusercontent.com/OCA/mail/19.0/mail_tracking/static/src/img/opened.png
122+
.. |cc| image:: https://raw.githubusercontent.com/OCA/mail/19.0/mail_tracking/static/src/img/cc.png
123+
.. |noemail| image:: https://raw.githubusercontent.com/OCA/mail/19.0/mail_tracking/static/src/img/no_email.png
124+
.. |anonuser| image:: https://raw.githubusercontent.com/OCA/mail/19.0/mail_tracking/static/src/img/anon_user.png
125+
.. |image| image:: https://raw.githubusercontent.com/OCA/mail/19.0/mail_tracking/static/img/failed_message_discuss.png
126+
.. |image1| image:: https://raw.githubusercontent.com/OCA/mail/19.0/mail_tracking/static/img/failed_message_widget.png
127+
.. |image2| image:: https://raw.githubusercontent.com/OCA/mail/19.0/mail_tracking/static/img/failed_message_filter.png
128128

129129
Known issues / Roadmap
130130
======================
@@ -139,7 +139,7 @@ Bug Tracker
139139
Bugs are tracked on `GitHub Issues <https://github.com/OCA/mail/issues>`_.
140140
In case of trouble, please check there if your issue has already been reported.
141141
If you spotted it first, help us to smash it by providing a detailed and welcomed
142-
`feedback <https://github.com/OCA/mail/issues/new?body=module:%20mail_tracking%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
142+
`feedback <https://github.com/OCA/mail/issues/new?body=module:%20mail_tracking%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
143143

144144
Do not contact contributors directly about support or help with technical issues.
145145

@@ -175,6 +175,10 @@ Contributors
175175

176176
- Tris Doan
177177

178+
- `Komit <https://komit-consulting.com>`__:
179+
180+
- Quoc Pham Ngoc
181+
178182
Other credits
179183
-------------
180184

@@ -194,6 +198,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
194198
mission is to support the collaborative development of Odoo features and
195199
promote its widespread use.
196200

197-
This module is part of the `OCA/mail <https://github.com/OCA/mail/tree/18.0/mail_tracking>`_ project on GitHub.
201+
This module is part of the `OCA/mail <https://github.com/OCA/mail/tree/19.0/mail_tracking>`_ project on GitHub.
198202

199203
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

mail_tracking/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
from . import controllers
22
from . import models
3-
from . import wizards

mail_tracking/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "Email tracking",
99
"summary": "Email tracking system for all mails sent",
10-
"version": "18.0.1.0.8",
10+
"version": "19.0.1.0.0",
1111
"category": "Social Network",
1212
"website": "https://github.com/OCA/mail",
1313
"author": ("Tecnativa, Odoo Community Association (OCA)"),

mail_tracking/controllers/mailbox.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
class MailTrackingMailBoxController(MailboxController):
10-
@route("/mail/failed/messages", methods=["POST"], type="json", auth="user")
10+
@route("/mail/failed/messages", methods=["POST"], type="jsonrpc", auth="user")
1111
def discuss_failed_messages(
1212
self, search_term=None, before=None, after=None, limit=30, around=None
1313
):
@@ -23,6 +23,6 @@ def discuss_failed_messages(
2323
messages = res.pop("messages")
2424
return {
2525
**res,
26-
"data": Store(messages, for_current_user=True).get_result(),
27-
"messages": Store.many_ids(messages),
26+
"data": Store().add(messages).get_result(),
27+
"messages": messages.ids,
2828
}

mail_tracking/models/ir_mail_server.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def _tracking_img_remove(self, body):
3838
r'<img[^>]*data-odoo-tracking-email=["\'][0-9]*["\'][^>]*>', "", body
3939
)
4040

41-
def build_email(
41+
def _build_email__(
4242
self,
4343
email_from,
4444
email_to,
@@ -78,11 +78,11 @@ def build_email(
7878
# the tracking image in case it's to be disabled
7979
if self._tracking_img_disabled(tracking_email_id):
8080
body = self._tracking_img_remove(body)
81-
msg = super().build_email(
82-
email_from=email_from,
83-
email_to=email_to,
84-
subject=subject,
85-
body=body,
81+
return super()._build_email__(
82+
email_from,
83+
email_to,
84+
subject,
85+
body,
8686
email_cc=email_cc,
8787
email_bcc=email_bcc,
8888
reply_to=reply_to,
@@ -95,7 +95,6 @@ def build_email(
9595
body_alternative=body_alternative,
9696
subtype_alternative=subtype_alternative,
9797
)
98-
return msg
9998

10099
def _tracking_email_get(self, message):
101100
try:

mail_tracking/models/mail_alias.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ def get_aliases(self):
1515
x["display_name"]
1616
for x in self.search_read([("alias_name", "!=", False)], ["display_name"])
1717
}
18-
mail_alias_domain = self.env["mail.alias.domain"].search([])
18+
mail_alias_domain = self.env["mail.alias.domain"].search_fetch(
19+
[], field_names=["catchall_email", "default_from", "default_from_email"]
20+
)
1921
catchall_emails = set(mail_alias_domain.mapped("catchall_email"))
2022
default_from_emails = set(
2123
mail_alias_domain.filtered("default_from").mapped("default_from_email")

mail_tracking/models/mail_mail.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ def _tracking_email_prepare(self, email):
2828
"sender": self.email_from,
2929
}
3030

31-
def _prepare_outgoing_list(
32-
self, mail_server=False, recipients_follower_status=None
33-
):
31+
def _prepare_outgoing_list(self, mail_server=False, doc_to_followers=None):
3432
"""Creates the mail.tracking.email record and adds the image tracking
3533
to the email. Please note that because we can't add mail headers in this
3634
function, the added tracking image will later (IrMailServer.build_email)
3735
also be used to extract the mail.tracking.email record id and to set the
3836
X-Odoo-MailTracking-ID header there.
3937
"""
40-
emails = super()._prepare_outgoing_list(mail_server, recipients_follower_status)
38+
emails = super()._prepare_outgoing_list(
39+
mail_server=mail_server,
40+
doc_to_followers=doc_to_followers,
41+
)
4142
tracking_vals_list = [self._tracking_email_prepare(email) for email in emails]
4243
trackings = self.env["mail.tracking.email"].sudo().create(tracking_vals_list)
4344
for email, tracking in zip(emails, trackings, strict=True):

mail_tracking/models/mail_message.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from email.utils import getaddresses
66

77
from odoo import api, fields, models
8-
from odoo.osv import expression
8+
from odoo.fields import Domain
99
from odoo.tools import email_split
1010

1111
from odoo.addons.mail.tools.discuss import Store
@@ -22,7 +22,7 @@ class MailMessage(models.Model):
2222
mail_tracking_ids = fields.One2many(
2323
comodel_name="mail.tracking.email",
2424
inverse_name="mail_message_id",
25-
auto_join=True,
25+
bypass_search_access=True,
2626
string="Mail Trackings",
2727
)
2828
mail_tracking_needs_action = fields.Boolean(
@@ -73,7 +73,7 @@ def _search_is_failed_message(self, operator, operand):
7373
)
7474
self.env["mail.notification"].flush_model(["mail_message_id", "res_partner_id"])
7575
self.env["mail.tracking.email"].flush_model(["state"])
76-
is_involve = expression.OR(
76+
is_involve = Domain.OR(
7777
[
7878
[
7979
("notification_ids.res_partner_id", "=", pid),
@@ -83,7 +83,7 @@ def _search_is_failed_message(self, operator, operand):
8383
],
8484
]
8585
)
86-
domain = expression.AND(
86+
domain = Domain.AND(
8787
[
8888
[
8989
(
@@ -177,7 +177,7 @@ def tracking_status(self):
177177
"recipient": recipient,
178178
"partner_id": tracking.partner_id.id,
179179
"isCc": False,
180-
"tracking_delta": "%i-%i" % (self.id, tracking_delta),
180+
"tracking_delta": f"{self.id}-{tracking_delta}",
181181
}
182182
)
183183
if tracking.partner_id:
@@ -218,7 +218,7 @@ def tracking_status(self):
218218
"recipient": partner.name,
219219
"partner_id": partner.id,
220220
"isCc": isCc,
221-
"tracking_delta": "%i-%i" % (self.id, tracking_delta),
221+
"tracking_delta": f"{self.id}-{tracking_delta}",
222222
}
223223
)
224224
partner_trackings.append(tracking_status)
@@ -232,7 +232,7 @@ def tracking_status(self):
232232
"recipient": email,
233233
"partner_id": False,
234234
"isCc": cc,
235-
"tracking_delta": "%i-%i" % (self.id, tracking_delta),
235+
"tracking_delta": f"{self.id}-{tracking_delta}",
236236
}
237237
)
238238
partner_trackings.append(tracking_status)

mail_tracking/models/mail_thread.py

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from lxml import etree
77

88
from odoo import api, fields, models
9-
from odoo.tools.mail import email_split, email_split_and_format
9+
from odoo.tools.mail import email_split_and_format_normalize
1010

1111

1212
class MailThread(models.AbstractModel):
@@ -62,42 +62,27 @@ def _routing_handle_bounce(self, email_message, message_dict):
6262
mail_trackings.event_create("soft_bounce", message_dict)
6363
return super()._routing_handle_bounce(email_message, message_dict)
6464

65-
def _message_get_suggested_recipients(self):
66-
"""Adds email 'extra' recipients as suggested recipients.
67-
68-
If the recipient has a res.partner, use it.
69-
"""
70-
res = super()._message_get_suggested_recipients()
71-
self._add_extra_recipients_suggestions(res, "email_cc", self.env._("Cc"))
72-
self._add_extra_recipients_suggestions(res, "email_to", self.env._("Anon. To"))
73-
return res
74-
75-
def _add_extra_recipients_suggestions(self, suggestions, field_mail, reason):
76-
ResPartnerObj = self.env["res.partner"]
77-
aliases = self.env["mail.alias"].get_aliases()
78-
email_extra_formated_list = []
65+
def _message_add_suggested_recipients(self, force_primary_email=False):
66+
suggested = super()._message_add_suggested_recipients(
67+
force_primary_email=force_primary_email
68+
)
7969
for record in self:
80-
emails_extra = record.message_ids.mapped(field_mail)
81-
for email in emails_extra:
82-
email_extra_formated_list.extend(email_split_and_format(email))
83-
email_extra_formated_list = set(email_extra_formated_list)
84-
email_extra_list = [x[1] for x in getaddresses(email_extra_formated_list)]
85-
partners_info = self.sudo()._message_partner_info_from_emails(email_extra_list)
86-
for pinfo in partners_info:
87-
partner_id = pinfo["partner_id"]
88-
email_formed = email_split(pinfo["full_name"])
89-
email = email_formed and email_formed[0].lower()
90-
if not partner_id:
91-
if email not in aliases:
92-
self._message_add_suggested_recipient(
93-
suggestions, email=email, reason=reason
94-
)
95-
else:
96-
partner = ResPartnerObj.browse(partner_id)
97-
if partner.email not in aliases:
98-
self._message_add_suggested_recipient(
99-
suggestions, partner=partner, reason=reason
100-
)
70+
self._add_extra_recipients_suggestions(record, suggested, "email_cc")
71+
self._add_extra_recipients_suggestions(record, suggested, "email_to")
72+
return suggested
73+
74+
def _add_extra_recipients_suggestions(self, record, suggestions, field_mail):
75+
email_extra_formatted_list = []
76+
emails_extra = record.message_ids.mapped(field_mail)
77+
for email in emails_extra:
78+
email_extra_formatted_list.extend(email_split_and_format_normalize(email))
79+
email_extra_formatted_list = set(email_extra_formatted_list)
80+
email_extra_list = [x[1] for x in getaddresses(email_extra_formatted_list)]
81+
for email in email_extra_list:
82+
if email not in suggestions[record.id]["email_to_lst"]:
83+
suggestions[record.id]["email_to_lst"] += (
84+
email_split_and_format_normalize(email)
85+
)
10186

10287
@api.model
10388
def get_view(self, view_id=None, view_type="form", **options):

mail_tracking/models/mail_tracking_email.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,14 @@ def write(self, vals):
140140
return res
141141

142142
@api.model
143-
def _search(
144-
self,
145-
domain,
146-
offset=0,
147-
limit=None,
148-
order=None,
149-
):
143+
def _search(self, domain, offset=0, limit=None, order=None, **kwargs):
150144
"""Override that adds specific access rights of mail.tracking.email, to remove
151145
ids uid could not see according to our custom rules. Please refer to
152146
_check_access() for more details about those rules.
153147
"""
154-
query = super()._search(domain, offset, limit, order)
148+
query = super()._search(
149+
domain, offset=offset, limit=limit, order=order, **kwargs
150+
)
155151
if not self.env.is_superuser():
156152
records = self.browse(query)
157153
allowed_ids = self._get_allowed_ids(records.ids)
@@ -289,12 +285,12 @@ def _email_last_tracking_state(self, email):
289285
def email_score_from_email(self, email):
290286
if not email:
291287
return 0.0
292-
data = self.sudo().read_group(
293-
[("recipient_address", "=", email.lower())],
294-
["recipient_address", "state"],
295-
["state"],
288+
groups = self.sudo()._read_group(
289+
domain=[("recipient_address", "=", email.lower())],
290+
groupby=["state"],
291+
aggregates=["recipient_address:count"],
296292
)
297-
mapped_data = {state["state"]: state["state_count"] for state in data}
293+
mapped_data = {state: count for (state, count) in groups}
298294
return self.with_context(mt_states=mapped_data).sudo().email_score()
299295

300296
@api.model

0 commit comments

Comments
 (0)