Skip to content

Commit

Permalink
[MIG] mail_autogenerated_header: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaniszewska-dev committed Sep 18, 2024
1 parent 7ffad87 commit c4f88f1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 39 deletions.
2 changes: 1 addition & 1 deletion mail_autogenerated_header/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Autogenerated headers",
"version": "12.0.1.0.0",
"version": "17.0.1.0.0",
"author": "Hunki Enterprises BV, Therp BV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social",
"license": "AGPL-3",
Expand Down
1 change: 0 additions & 1 deletion mail_autogenerated_header/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import ir_mail_server
from . import mail_thread
from . import res_partner
10 changes: 9 additions & 1 deletion mail_autogenerated_header/models/ir_mail_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def send_email(
smtp_user=None,
smtp_password=None,
smtp_encryption=None,
smtp_ssl_certificate=None,
smtp_ssl_private_key=None,
smtp_debug=False,
smtp_session=None,
):
Expand All @@ -32,6 +34,8 @@ def send_email(
smtp_user=smtp_user,
smtp_password=smtp_password,
smtp_encryption=smtp_encryption,
smtp_ssl_certificate=smtp_ssl_certificate,
smtp_ssl_private_key=smtp_ssl_private_key,
smtp_debug=smtp_debug,
smtp_session=smtp_session,
):
Expand All @@ -44,14 +48,16 @@ def send_email(
# https://tools.ietf.org/html/rfc3834
message["Auto-Submitted"] = "auto-generated"

return super(IrMailServer, self).send_email(
return super().send_email(
message,
mail_server_id=mail_server_id,
smtp_server=smtp_server,
smtp_port=smtp_port,
smtp_user=smtp_user,
smtp_password=smtp_password,
smtp_encryption=smtp_encryption,
smtp_ssl_certificate=smtp_ssl_certificate,
smtp_ssl_private_key=smtp_ssl_private_key,
smtp_debug=smtp_debug,
smtp_session=smtp_session,
)
Expand All @@ -66,6 +72,8 @@ def _send_email_set_autogenerated(
smtp_user=None,
smtp_password=None,
smtp_encryption=None,
smtp_ssl_certificate=None,
smtp_ssl_private_key=None,
smtp_debug=False,
smtp_session=None,
):
Expand Down
11 changes: 9 additions & 2 deletions mail_autogenerated_header/models/mail_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MailThread(models.AbstractModel):
_inherit = "mail.thread"

@api.model
def message_route_process(self, message, message_dict, routes):
def _message_route_process(self, message, message_dict, routes):
"""Set context key to suppress notification for autogenerated incoming
mails"""
if self._message_route_process_autoreply(message, message_dict, routes):
Expand All @@ -22,12 +22,19 @@ def message_route_process(self, message, message_dict, routes):
message.get("From"),
)
self = self.with_context(mail_autogenerated_header=message)
return super(MailThread, self).message_route_process(
return super().message_route_process(
message,
message_dict,
routes,
)

def _notify_thread(self, message, msg_vals=False, **kwargs):
"""Inhibit notifications if this is the notification for an incoming
autogenerated mail from another system"""
if self.env.context.get("mail_autogenerated_header"):
return False
return super()._notify_thread(message, msg_vals=msg_vals, **kwargs)

@api.model
def _message_route_process_autoreply(self, message, message_dict, routes):
"""Determine if some message is an autoreply"""
Expand Down
32 changes: 0 additions & 32 deletions mail_autogenerated_header/models/res_partner.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def test_receiving(self):
"Message-Id",
generate_tracking_message_id(42),
)

self.env["mail.notification"].search(
[("res_partner_id", "=", demo_user.partner_id.id)]
).unlink()

partner_id = self.env["mail.thread"].message_process(
"res.partner",
self.message.as_string(),
Expand All @@ -55,7 +60,7 @@ def test_receiving(self):
[("res_partner_id", "=", demo_user.partner_id.id)]
)
# mail is not autogenerated, should have generated mails
self.assertTrue(notifications.is_email)
self.assertTrue(notifications.notification_type == "email")
notifications.unlink()

reply.replace_header("Message-Id", "message_id4")
Expand All @@ -69,4 +74,4 @@ def test_receiving(self):
[("res_partner_id", "=", demo_user.partner_id.id)]
)
# mail is autogenerated, shouldn't have generated mails
self.assertFalse(notifications.is_email)
self.assertFalse(notifications.notification_type == "email")

0 comments on commit c4f88f1

Please sign in to comment.