From c4f88f1915df9d60fe4b0d1a70bdd9ea52ac3319 Mon Sep 17 00:00:00 2001 From: Anna Janiszewska Date: Thu, 12 Sep 2024 14:46:28 +0200 Subject: [PATCH] [MIG] mail_autogenerated_header: Migration to 17.0 --- mail_autogenerated_header/__manifest__.py | 2 +- mail_autogenerated_header/models/__init__.py | 1 - .../models/ir_mail_server.py | 10 +++++- .../models/mail_thread.py | 11 +++++-- .../models/res_partner.py | 32 ------------------- .../tests/test_mail_autogenerated_header.py | 9 ++++-- 6 files changed, 26 insertions(+), 39 deletions(-) delete mode 100644 mail_autogenerated_header/models/res_partner.py diff --git a/mail_autogenerated_header/__manifest__.py b/mail_autogenerated_header/__manifest__.py index 2cbce4df12..61cc6301e6 100644 --- a/mail_autogenerated_header/__manifest__.py +++ b/mail_autogenerated_header/__manifest__.py @@ -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", diff --git a/mail_autogenerated_header/models/__init__.py b/mail_autogenerated_header/models/__init__.py index af47c23c8c..0ce24b0b12 100644 --- a/mail_autogenerated_header/models/__init__.py +++ b/mail_autogenerated_header/models/__init__.py @@ -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 diff --git a/mail_autogenerated_header/models/ir_mail_server.py b/mail_autogenerated_header/models/ir_mail_server.py index af99da88be..c83447e59d 100644 --- a/mail_autogenerated_header/models/ir_mail_server.py +++ b/mail_autogenerated_header/models/ir_mail_server.py @@ -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, ): @@ -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, ): @@ -44,7 +48,7 @@ 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, @@ -52,6 +56,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, ) @@ -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, ): diff --git a/mail_autogenerated_header/models/mail_thread.py b/mail_autogenerated_header/models/mail_thread.py index 063ca410db..f4893f4c31 100644 --- a/mail_autogenerated_header/models/mail_thread.py +++ b/mail_autogenerated_header/models/mail_thread.py @@ -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): @@ -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""" diff --git a/mail_autogenerated_header/models/res_partner.py b/mail_autogenerated_header/models/res_partner.py deleted file mode 100644 index e905570f6f..0000000000 --- a/mail_autogenerated_header/models/res_partner.py +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2022 Hunki Enterprises BV -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import api, models - - -class ResPartner(models.Model): - _inherit = "res.partner" - - @api.model - def _notify( - self, - message, - rdata, - record, - force_send=False, - send_after_commit=True, - model_description=False, - mail_auto_delete=True, - ): - """Inhibit notifications if this is the notification for an incoming - autogenerated mail from another system""" - if self.env.context.get("mail_autogenerated_header"): - return True - return super()._notify( - message, - rdata, - record, - force_send=force_send, - send_after_commit=send_after_commit, - model_description=model_description, - mail_auto_delete=mail_auto_delete, - ) diff --git a/mail_autogenerated_header/tests/test_mail_autogenerated_header.py b/mail_autogenerated_header/tests/test_mail_autogenerated_header.py index f97b15468a..f018da2baf 100644 --- a/mail_autogenerated_header/tests/test_mail_autogenerated_header.py +++ b/mail_autogenerated_header/tests/test_mail_autogenerated_header.py @@ -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(), @@ -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") @@ -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")