From bb5b211d9c395560d241a18c5b0e724d30dad596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20V=C3=A9zina?= Date: Mon, 24 Feb 2025 09:53:36 -0500 Subject: [PATCH] block notification on msg import --- .../models/__init__.py | 1 + .../models/ir_attachment.py | 28 +++++++++---------- .../models/mail_thread.py | 23 +++++++++++++++ 3 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 msg_attachments_to_mail_message/models/mail_thread.py diff --git a/msg_attachments_to_mail_message/models/__init__.py b/msg_attachments_to_mail_message/models/__init__.py index 075fb0e..28ba0f2 100644 --- a/msg_attachments_to_mail_message/models/__init__.py +++ b/msg_attachments_to_mail_message/models/__init__.py @@ -1,2 +1,3 @@ from . import ir_attachment +from . import mail_thread from . import res_config_settings diff --git a/msg_attachments_to_mail_message/models/ir_attachment.py b/msg_attachments_to_mail_message/models/ir_attachment.py index c4e473e..fa65dd7 100644 --- a/msg_attachments_to_mail_message/models/ir_attachment.py +++ b/msg_attachments_to_mail_message/models/ir_attachment.py @@ -435,11 +435,14 @@ class IrAttachment(models.Model): target_thread_id = self.res_id if self.res_model else False # Process the email with forced model - self.env['mail.thread'].with_context( - mail_create_nosubscribe=True, # Don't auto-subscribe the sender - mail_create_nolog=True, # Don't create log message - default_model=target_model, # Force the model - ).message_process( + context = { + 'default_model': target_model, # Force the model + 'mail_notify_force_send': False, # Don't force send notifications + 'mail_auto_subscribe_no_notify': True, # Prevent auto-subscription notifications + 'is_msg_import': True, # Flag to identify MSG import + } + + self.env['mail.thread'].with_context(**context).message_process( model=target_model, message=eml_content, custom_values=custom_values, @@ -657,16 +660,11 @@ class IrAttachment(models.Model): # Set context for message creation context = { - "default_model": self.res_model, - "default_res_id": self.res_id, - "mail_create_nosubscribe": True, - "mail_create_nolog": True, - "mail_notify_force_send": False, - "mail_create_force_model": self.res_model, - "mail_thread_quote": False, - "mail_create_skip_followers": True, - "mail_auto_subscribe_no_notify": True, # Prevent auto-subscription notifications - "no_auto_thread": True # Prevent automatic thread creation + 'default_model': self.res_model, + 'default_res_id': self.res_id, + 'mail_notify_force_send': False, # Don't force send notifications + 'mail_auto_subscribe_no_notify': True, # Prevent auto-subscription notifications + 'is_msg_import': True, # Flag to identify MSG import } try: diff --git a/msg_attachments_to_mail_message/models/mail_thread.py b/msg_attachments_to_mail_message/models/mail_thread.py new file mode 100644 index 0000000..eb6a6ea --- /dev/null +++ b/msg_attachments_to_mail_message/models/mail_thread.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from odoo import models, api +from odoo.tools import email_normalize + + +class MailThread(models.AbstractModel): + _inherit = 'mail.thread' + + def _notify_thread(self, message, msg_vals=False, **kwargs): + """Override _notify_thread to disable notifications for MSG file imports. + + When processing a message that comes from an MSG file import, we want to + disable all notifications to avoid sending automatic responses. + + Returns: + list: Empty list of recipients when is_msg_import is True, otherwise normal recipients data + """ + # Check if this is called from MSG processing + if self.env.context.get('is_msg_import', False): + # Return empty recipients list for MSG imports + return [] + + return super()._notify_thread(message, msg_vals=msg_vals, **kwargs)