Skip to content

Commit

Permalink
[MIG] mail_tracking: Migration to 17.0
Browse files Browse the repository at this point in the history
TT49060
  • Loading branch information
chienandalu authored and pedrobaeza committed Jun 11, 2024
1 parent 549006c commit e981f3c
Show file tree
Hide file tree
Showing 73 changed files with 1,208 additions and 1,290 deletions.
19 changes: 3 additions & 16 deletions mail_tracking/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ records with messages in failed status and that needs an user action.
Known issues / Roadmap
======================

- Integrate with the core mail.notification model. A soft way would be
to write a notification event along with the mail.tracking.event
ones. Another way could be to merge both models and build the module
features on top of it. This might imply a refactor though.
- Integrate with the core ``mail.notification`` model as it overlaps
with what the ``mail.tracking`` model does. We could add the existing
features on top of that model and save lots of code lines.

Bug Tracker
===========
Expand Down Expand Up @@ -168,18 +167,6 @@ Contributors

- Agustín Payen Sandoval

Other credits
-------------

Images
~~~~~~

- Odoo Community Association:
`Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`__.
- Thanks to `LlubNek <https://openclipart.org/user-detail/LlubNek>`__
and `Openclipart <https://openclipart.org>`__ for `the
icon <https://openclipart.org/detail/19342/open-envelope>`__.

Maintainers
-----------

Expand Down
5 changes: 2 additions & 3 deletions mail_tracking/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
from . import controllers
from . import models
from . import wizards
43 changes: 13 additions & 30 deletions mail_tracking/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Copyright 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
# Copyright 2018 David Vidal - <david.vidal@tecnativa.com>
# Copyright 2016 Tecnativa - Antonio Espinosa
# Copyright 2018 Tecnativa - David Vidal
# Copyright 2018 Tecnativa - Ernesto Tejeda
# Copyright 2019 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Email tracking",
"summary": "Email tracking system for all mails sent",
"version": "16.0.1.0.4",
"version": "17.0.1.0.0",
"category": "Social Network",
"website": "https://github.com/OCA/social",
"author": ("Tecnativa, " "Odoo Community Association (OCA)"),
"author": ("Tecnativa, Odoo Community Association (OCA)"),
"license": "AGPL-3",
"application": False,
"installable": True,
Expand All @@ -26,32 +26,15 @@
],
"assets": {
"web.assets_backend": [
"mail_tracking/static/src/client_actions/failed_message_storage.esm.js",
"mail_tracking/static/src/models/chatter.esm.js",
"mail_tracking/static/src/models/discuss_sidebar_mailbox_view.esm.js",
"mail_tracking/static/src/models/discuss_view.esm.js",
"mail_tracking/static/src/models/mailbox.esm.js",
"mail_tracking/static/src/models/message_list_view_item.esm.js",
"mail_tracking/static/src/models/message_list_view.esm.js",
"mail_tracking/static/src/models/message_view.esm.js",
"mail_tracking/static/src/models/message.esm.js",
"mail_tracking/static/src/models/messaging_initializer.esm.js",
"mail_tracking/static/src/models/messaging.esm.js",
"mail_tracking/static/src/models/thread.esm.js",
"mail_tracking/static/src/components/discuss/discuss.xml",
"mail_tracking/static/src/components/message/message.xml",
"mail_tracking/static/src/components/message/message.esm.js",
"mail_tracking/static/src/components/message/message.scss",
"mail_tracking/static/src/components/message_list/message_list.esm.js",
"mail_tracking/static/src/components/failed_message/failed_message.xml",
"mail_tracking/static/src/components/failed_message/failed_message.esm.js",
"mail_tracking/static/src/components/failed_message/failed_message.scss",
"mail_tracking/static/src/components/failed_message_list/failed_message_list.xml",
"mail_tracking/static/src/components/failed_message_list/failed_message_list.esm.js", # noqa: B950
"mail_tracking/static/src/components/discuss_sidebar_mailbox/discuss_sidebar_mailbox.xml", # noqa: B950
"mail_tracking/static/src/components/discuss_sidebar_mailbox/discuss_sidebar_mailbox.esm.js", # noqa: B950
"mail_tracking/static/src/components/thread_view/thread_view.xml",
"mail_tracking/static/src/components/thread_view/thread_view.scss",
"mail_tracking/static/src/core/chatter/*",
"mail_tracking/static/src/core/message/*",
"mail_tracking/static/src/core/search/*",
"mail_tracking/static/src/core/discuss/*",
"mail_tracking/static/src/services/*",
"mail_tracking/static/src/components/message_tracking/*",
"mail_tracking/static/src/components/failed_message/*",
"mail_tracking/static/src/components/failed_message_review/*",
"mail_tracking/static/src/components/failed_messages_panel/*",
],
},
"demo": ["demo/demo.xml"],
Expand Down
4 changes: 1 addition & 3 deletions mail_tracking/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import main
from . import discuss
from . import mailbox
28 changes: 0 additions & 28 deletions mail_tracking/controllers/discuss.py

This file was deleted.

22 changes: 22 additions & 0 deletions mail_tracking/controllers/mailbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.http import request, route

from odoo.addons.mail.controllers.mailbox import MailboxController


class MailTrackingMailBoxController(MailboxController):
@route("/mail/failed/messages", methods=["POST"], type="json", auth="user")
def discuss_failed_messages(
self, search_term=None, before=None, after=None, limit=30, around=None
):
"""Fetch failed messages for discuss"""
res = request.env["mail.message"]._message_fetch(

Check warning on line 14 in mail_tracking/controllers/mailbox.py

View check run for this annotation

Codecov / codecov/patch

mail_tracking/controllers/mailbox.py#L14

Added line #L14 was not covered by tests
[("is_failed_message", "=", True)],
search_term=search_term,
before=before,
after=after,
around=around,
limit=limit,
)
return {**res, "messages": res["messages"].message_format()}

Check warning on line 22 in mail_tracking/controllers/mailbox.py

View check run for this annotation

Codecov / codecov/patch

mail_tracking/controllers/mailbox.py#L22

Added line #L22 was not covered by tests
2 changes: 1 addition & 1 deletion mail_tracking/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _request_metadata(self):

@http.route(
[
"/mail/tracking/open/<string:db>" "/<int:tracking_email_id>/blank.gif",
"/mail/tracking/open/<string:db>/<int:tracking_email_id>/blank.gif",
"/mail/tracking/open/<string:db>"
"/<int:tracking_email_id>/<string:token>/blank.gif",
],
Expand Down
12 changes: 4 additions & 8 deletions mail_tracking/demo/demo.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="True">
<odoo noupdate="1">
<!-- Message with CC -->
<record id="mail_message_cc" model="mail.message">
<field name="model">res.partner</field>
Expand All @@ -16,10 +16,6 @@
<field
name="partner_ids"
eval="[Command.set([ref('base.partner_demo')])]"
/>
<field
name="notification_ids"
eval="[Command.create({'res_partner_id': ref('base.partner_demo')})]"
/>
<field name="subject">Message with CC</field>
</record>
Expand Down Expand Up @@ -50,7 +46,7 @@
/>
<field
name="notification_ids"
eval="[Command.create({'res_partner_id': ref('base.partner_demo')})]"
eval="[Command.create({'res_partner_id': ref('base.partner_demo')}),Command.create({'res_partner_id': ref('base.res_partner_1'), 'notification_status': 'exception'})]"
/>
<field name="subject">Failed Message</field>
</record>
Expand Down Expand Up @@ -81,7 +77,7 @@
/>
<field
name="notification_ids"
eval="[Command.create({'res_partner_id': ref('base.partner_demo')})]"
eval="[Command.create({'res_partner_id': ref('base.partner_demo')}),Command.create({'res_partner_id': ref('base.res_partner_10'), 'notification_status': 'bounce'})]"
/>
<field name="subject">Failed Message</field>
</record>
Expand Down Expand Up @@ -112,7 +108,7 @@
/>
<field
name="notification_ids"
eval="[Command.create({'res_partner_id': ref('base.partner_demo')})]"
eval="[Command.create({'res_partner_id': ref('base.partner_demo')}),Command.create({'res_partner_id': ref('base.partner_admin'), 'notification_status': 'exception'})]"
/>
<field name="subject">Failed Message</field>
</record>
Expand Down
5 changes: 3 additions & 2 deletions mail_tracking/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

from . import ir_mail_server
from . import mail_bounced_mixin
from . import mail_guest
from . import mail_mail
from . import mail_message
from . import mail_tracking_email
from . import mail_tracking_event
from . import res_partner
from . import mail_thread
from . import mail_resend_message
from . import mail_alias
from . import ir_config_parameter
from . import mail_alias_domain
from . import res_users
24 changes: 0 additions & 24 deletions mail_tracking/models/ir_config_parameter.py

This file was deleted.

4 changes: 2 additions & 2 deletions mail_tracking/models/ir_mail_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def build_email(
# the tracking image in case it's to be disabled
if self._tracking_img_disabled(tracking_email_id):
body = self._tracking_img_remove(body)
msg = super(IrMailServer, self).build_email(
msg = super().build_email(
email_from=email_from,
email_to=email_to,
subject=subject,
Expand Down Expand Up @@ -143,7 +143,7 @@ def send_email(
tracking_email = self._tracking_email_get(message)
smtp_server_used = self.sudo()._smtp_server_get(mail_server_id, smtp_server)
try:
message_id = super(IrMailServer, self).send_email(
message_id = super().send_email(
message,
mail_server_id=mail_server_id,
smtp_server=smtp_server,
Expand Down
18 changes: 9 additions & 9 deletions mail_tracking/models/mail_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ class MailAlias(models.Model):
@api.model
@tools.ormcache()
def get_aliases(self):
"""We want to discard these addresses for trackings"""
aliases = {
x["display_name"]
for x in self.search_read([("alias_name", "!=", False)], ["display_name"])
}
IrConfigParamObj = self.env["ir.config_parameter"].sudo()
catchall = "{}@{}".format(
IrConfigParamObj.get_param("mail.catchall.alias"),
IrConfigParamObj.get_param("mail.catchall.domain"),
mail_alias_domain = self.env["mail.alias.domain"].search([])
catchall_emails = set(mail_alias_domain.mapped("catchall_email"))
default_from_emails = set(
mail_alias_domain.filtered("default_from").mapped("default_from_email")
)
aliases.add(catchall)
return aliases
return aliases | catchall_emails | default_from_emails

@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)
self.clear_caches()
self.env.registry.clear_cache()
return res

def write(self, vals):
res = super().write(vals)
if "alias_name" in vals:
self.clear_caches()
self.env.registry.clear_cache()
return res

def unlink(self):
res = super().unlink()
self.clear_caches()
self.env.registry.clear_cache()
return res
32 changes: 32 additions & 0 deletions mail_tracking/models/mail_alias_domain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2020 Tecnativa - Alexandre Díaz
# Copyright 2024 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class MailAliasDomain(models.Model):
_inherit = "mail.alias.domain"

@api.model_create_multi
def create(self, vals_list):
"""We've got `mail.alias.get_aliases` method which is cached os we need
to refresh the cache when we add a new alias domain"""
res = super().create(vals_list)
self.env.registry.clear_cache()
return res

def write(self, vals):
"""We've got `mail.alias.get_aliases` method which is cached os we need
to refresh the cache when we add a new alias domain"""
res = super().write(vals)
if "catchall_alias" in vals:
self.env.registry.clear_cache()
return res

def unlink(self):
"""We've got `mail.alias.get_aliases` method which is cached os we need
to refresh the cache when we remove an alias domain"""
res = super().unlink()
self.env.registry.clear_cache()
return res
13 changes: 13 additions & 0 deletions mail_tracking/models/mail_guest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2024 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models


class MailGuest(models.Model):
_inherit = "mail.guest"

def _init_messaging(self):
"""For discuss"""
values = super()._init_messaging()
values["failed_counter"] = False
return values
16 changes: 9 additions & 7 deletions mail_tracking/models/mail_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class MailMail(models.Model):
_inherit = "mail.mail"

def _tracking_email_prepare(self, partner, email):
def _tracking_email_prepare(self, email):
"""Prepare email.tracking.email record values"""
ts = time.time()
dt = datetime.utcfromtimestamp(ts)
Expand All @@ -23,19 +23,21 @@ def _tracking_email_prepare(self, partner, email):
"time": fields.Datetime.to_string(dt),
"mail_id": self.id,
"mail_message_id": self.mail_message_id.id,
"partner_id": partner.id if partner else False,
"partner_id": (email.get("partner_id") or self.env["res.partner"]).id,
"recipient": email_to,
"sender": self.email_from,
}

def _send_prepare_values(self, partner=None):
def _prepare_outgoing_list(self, recipients_follower_status=None):
"""Creates the mail.tracking.email record and adds the image tracking
to the email. Please note that because we can't add mail headers in this
function, the added tracking image will later (IrMailServer.build_email)
also be used to extract the mail.tracking.email record id and to set the
X-Odoo-MailTracking-ID header there.
"""
email = super()._send_prepare_values(partner=partner)
vals = self._tracking_email_prepare(partner, email)
tracking_email = self.env["mail.tracking.email"].sudo().create(vals)
return tracking_email.tracking_img_add(email)
emails = super()._prepare_outgoing_list(recipients_follower_status)
for email in emails:
vals = self._tracking_email_prepare(email)
tracking_email = self.env["mail.tracking.email"].sudo().create(vals)
tracking_email.tracking_img_add(email)
return emails
Loading

0 comments on commit e981f3c

Please sign in to comment.