From 7325633d495b30cec98b3688304fe7c055859164 Mon Sep 17 00:00:00 2001 From: Kristof Bernaert Date: Mon, 26 Jan 2026 04:27:39 +0100 Subject: [PATCH] Fix allow_mail_archived_partner causing system notifications to send emails --- .../models/account_move_send.py | 25 ++++++--------- .../models/mail_compose_message.py | 31 +------------------ .../models/mail_template.py | 8 ++--- .../models/res_partner.py | 25 +++------------ 4 files changed, 16 insertions(+), 73 deletions(-) diff --git a/allow_mail_archived_partner/models/account_move_send.py b/allow_mail_archived_partner/models/account_move_send.py index a760faa..5f76071 100755 --- a/allow_mail_archived_partner/models/account_move_send.py +++ b/allow_mail_archived_partner/models/account_move_send.py @@ -1,6 +1,3 @@ -import logging -_logger = logging.getLogger(__name__) - from odoo import models, api, fields @@ -18,8 +15,9 @@ class AccountInvoiceSend(models.TransientModel): @api.model def default_get(self, fields): - _logger.error("🔥 ACCOUNT.INVOICE.SEND default_get") - + """ + Pre-fill invoice email wizard with archived partners. + """ res = super().default_get(fields) active_ids = self.env.context.get('active_ids', []) @@ -31,16 +29,13 @@ class AccountInvoiceSend(models.TransientModel): partners = moves.mapped('partner_id').filtered(lambda p: p.email) if partners: res['partner_ids'] = [(6, 0, partners.ids)] - _logger.error(f"🔥 Set partner_ids: {res['partner_ids']}") return res def action_send_and_print(self): - _logger.error("🔥🔥🔥 ACCOUNT.INVOICE.SEND action_send_and_print CALLED 🔥🔥🔥") - _logger.error(f"🔥 Wizard ID: {self.id}") - _logger.error(f"🔥 Partner IDs: {self.partner_ids.ids}") # This returns a list of IDs - - # Call parent with context AND ensure partner_ids are passed + """ + Pass context to allow archived partners during email sending. + """ return super( AccountInvoiceSend, self.with_context( @@ -49,15 +44,13 @@ class AccountInvoiceSend(models.TransientModel): mail_notify_force=True, force_email=True, mark_invoice_as_sent=True, - # Pass simple list of IDs, NOT ORM tuple format - invoice_partner_ids=self.partner_ids.ids if self.partner_ids else [], ) ).action_send_and_print() def _get_composer_values(self, res_ids, template): - _logger.error("🔥 ACCOUNT.INVOICE.SEND _get_composer_values") - - # Also pass context to composer + """ + Pass context to mail composer to allow archived partners. + """ return super( AccountInvoiceSend, self.with_context( diff --git a/allow_mail_archived_partner/models/mail_compose_message.py b/allow_mail_archived_partner/models/mail_compose_message.py index e408b13..739cc85 100755 --- a/allow_mail_archived_partner/models/mail_compose_message.py +++ b/allow_mail_archived_partner/models/mail_compose_message.py @@ -1,6 +1,3 @@ -import logging -_logger = logging.getLogger(__name__) - from odoo import models, api @@ -13,8 +10,6 @@ class MailComposeMessage(models.TransientModel): Pre-fill email wizard with archived partners for sales orders. For invoices, this is handled by account.invoice.send. """ - _logger.debug("=== MAIL.COMPOSE.MESSAGE DEFAULT_GET ===") - res = super().default_get(fields) model = self.env.context.get("active_model") @@ -22,8 +17,6 @@ class MailComposeMessage(models.TransientModel): # Only handle sales orders here - invoices use account.invoice.send if model == "sale.order" and res_id: - _logger.debug(f"Processing sales order {res_id}") - # Find order with archived partners allowed order = self.env["sale.order"].with_context( active_test=False @@ -31,7 +24,6 @@ class MailComposeMessage(models.TransientModel): if order.exists() and order.partner_id: res["partner_ids"] = [(6, 0, [order.partner_id.id])] - _logger.debug(f"Pre-filled archived partner {order.partner_id.id} for sales order") return res @@ -40,14 +32,11 @@ class MailComposeMessage(models.TransientModel): Set context flags for manual email sends. This ensures archived partners are allowed during email sending. """ - _logger.debug("=== _prepare_mail_values ===") - model = self.env.context.get("active_model") or self.model # Only for sales orders and account moves (invoices) # Note: account.invoice.send should handle invoices, but keep this as fallback if model in ["sale.order", "account.move"]: - _logger.debug(f"Setting context for {model} to allow archived partners") return super( MailComposeMessage, self.with_context( @@ -74,7 +63,6 @@ class MailComposeMessage(models.TransientModel): # If it's a manual send and partner is archived, include them if is_manual_send and partner and not partner.active: - _logger.debug(f"Including archived partner {partner.name} in email") return { "partner_id": partner.id, "email": partner.email, @@ -83,21 +71,4 @@ class MailComposeMessage(models.TransientModel): } # Default behavior for active partners or non-manual sends - return super()._prepare_recipient_values(partner) - - - def action_send_mail(self): - """ - Log when email is actually sent. - """ - _logger.info("🔥 MAIL.COMPOSE.MESSAGE action_send_mail") - _logger.info(f"Partner IDs: {self.partner_ids.ids}") - _logger.info(f"Context: {dict(self.env.context)}") - return super().action_send_mail() - - def _action_send_mail(self, auto_commit=False): - """ - Another possible send method. - """ - _logger.info("🔥 MAIL.COMPOSE.MESSAGE _action_send_mail") - return super()._action_send_mail(auto_commit=auto_commit) \ No newline at end of file + return super()._prepare_recipient_values(partner) \ No newline at end of file diff --git a/allow_mail_archived_partner/models/mail_template.py b/allow_mail_archived_partner/models/mail_template.py index 9284329..cd6ec44 100755 --- a/allow_mail_archived_partner/models/mail_template.py +++ b/allow_mail_archived_partner/models/mail_template.py @@ -1,6 +1,3 @@ -import logging -_logger = logging.getLogger(__name__) - from odoo import models @@ -10,8 +7,7 @@ class MailTemplate(models.Model): 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 + that sets context['mail_notify_force'] = True. This prevents system notifications from inheriting your relaxed rules. """ @@ -24,4 +20,4 @@ class MailTemplate(models.Model): ) ).generate_email(res_ids, fields) - return super().generate_email(res_ids, fields) + return super().generate_email(res_ids, fields) \ No newline at end of file diff --git a/allow_mail_archived_partner/models/res_partner.py b/allow_mail_archived_partner/models/res_partner.py index b6e7d40..9b14033 100755 --- a/allow_mail_archived_partner/models/res_partner.py +++ b/allow_mail_archived_partner/models/res_partner.py @@ -1,6 +1,3 @@ -import logging -_logger = logging.getLogger(__name__) - from odoo import models, api @@ -10,13 +7,9 @@ class ResPartner(models.Model): @api.model def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None): """ - SIMPLE: Just remove active filters when context says to include archived. + Remove active filters when context indicates manual email send + (to allow finding archived partners). """ - _logger.error("🔥 RES.PARTNER._search - Checking for archived context") - _logger.error(f"🔥 Context force_email: {self.env.context.get('force_email')}") - _logger.error(f"🔥 Context mark_invoice_as_sent: {self.env.context.get('mark_invoice_as_sent')}") - _logger.error(f"🔥 Context mail_notify_force: {self.env.context.get('mail_notify_force')}") - # Check for manual email context include_archived = ( self.env.context.get("force_email") or @@ -24,11 +17,8 @@ class ResPartner(models.Model): self.env.context.get("mail_notify_force") ) - _logger.error(f"🔥 Should include archived? {include_archived}") - if include_archived: - _logger.error("🔥 Removing active filters for archived partners") - # Simple: remove active filters + # Remove active filters to include archived partners args = [ arg for arg in args if not (isinstance(arg, (list, tuple)) and @@ -36,12 +26,5 @@ class ResPartner(models.Model): arg[0] == "active") ] self = self.with_context(active_test=False) - _logger.error(f"🔥 Search args after: {args}") - result = super()._search(args, offset, limit, order, count, access_rights_uid) - - if not count: - result_ids = list(result) - _logger.error(f"🔥 Search returned {len(result_ids)} results") - - return result \ No newline at end of file + return super()._search(args, offset, limit, order, count, access_rights_uid) \ No newline at end of file