Fix allow_mail_archived_partner causing system notifications to send emails

This commit is contained in:
Kristof Bernaert
2026-01-26 04:33:59 +01:00
parent c94fba0f02
commit c175e33c03
5 changed files with 233 additions and 52 deletions
@@ -1,6 +1,25 @@
import logging
_logger = logging.getLogger(__name__)
from odoo import models
class MailTemplate(models.Model):
_inherit = "mail.template"
def generate_email(self, res_ids, fields=None):
"""
Only allow archived partners when *explicitly* sending through a flow
that sets:
context['mail_notify_force'] = True
This prevents system notifications from inheriting your relaxed rules.
"""
if self.model in ["sale.order", "account.move"] and self.env.context.get("mail_notify_force"):
return super(
MailTemplate,from odoo import models
class MailTemplate(models.Model):
_inherit = "mail.template"
@@ -20,4 +39,11 @@ class MailTemplate(models.Model):
)
).generate_email(res_ids, fields)
return super().generate_email(res_ids, fields)
return super().generate_email(res_ids, fields)
self.with_context(
active_test=False,
include_archived_partners=True
)
).generate_email(res_ids, fields)
return super().generate_email(res_ids, fields)