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,3 +1,6 @@
import logging
_logger = logging.getLogger(__name__)
from odoo import models, api, fields
@@ -15,9 +18,8 @@ class AccountInvoiceSend(models.TransientModel):
@api.model
def default_get(self, fields):
"""
Pre-fill invoice email wizard with archived partners.
"""
_logger.error("🔥 ACCOUNT.INVOICE.SEND default_get")
res = super().default_get(fields)
active_ids = self.env.context.get('active_ids', [])
@@ -29,13 +31,16 @@ 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):
"""
Pass context to allow archived partners during email sending.
"""
_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
return super(
AccountInvoiceSend,
self.with_context(
@@ -44,13 +49,15 @@ 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):
"""
Pass context to mail composer to allow archived partners.
"""
_logger.error("🔥 ACCOUNT.INVOICE.SEND _get_composer_values")
# Also pass context to composer
return super(
AccountInvoiceSend,
self.with_context(