Fix allow_mail_archived_partner causing system notifications to send emails

This commit is contained in:
Kristof Bernaert
2026-01-26 03:16:01 +01:00
parent 4d7f944d63
commit b7a1f1a600
@@ -1,60 +1,23 @@
import logging from odoo import models, api
_logger = logging.getLogger(__name__)
from odoo import models, api, fields
class AccountInvoiceSend(models.TransientModel): class AccountInvoiceSend(models.TransientModel):
_inherit = "account.invoice.send" _inherit = "account.invoice.send"
@api.model @api.model
def default_get(self, fields): def _get_default_mail_partner_ids(self, move, mail_template, mail_lang):
res = super().default_get(fields) """
Allow archived partners to be included as recipients when
active_ids = self.env.context.get('active_ids', []) sending invoices via the 'Send by Email' wizard.
if active_ids: This is the ONLY place where partner_ids are computed.
moves = self.env['account.move'].with_context( """
active_test=False # Temporarily disable active_test so archived partners are not filtered out
).browse(active_ids) wiz = self.with_context(
active_test=False,
partners = moves.mapped('partner_id').filtered(lambda p: p.email) include_archived_partners=True,
)
if partners:
res['partner_ids'] = [(6, 0, partners.ids)]
res['email_to'] = ", ".join(partners.mapped('email'))
return res
def action_send_and_print(self):
_logger.info("=== ACCOUNT.INVOICE.SEND action_send_and_print ===")
_logger.info(f"Wizard ID: {self.id}, Partners: {self.partner_ids.ids}")
return super( return super(
AccountInvoiceSend, AccountInvoiceSend,
self.with_context( wiz
active_test=False, )._get_default_mail_partner_ids(move, mail_template, mail_lang)
include_archived_partners=True,
mail_notify_force=True,
force_email=True,
mark_invoice_as_sent=True,
)
).action_send_and_print()
# LOG ALL POSSIBLE ACTIONS
def action_send(self):
_logger.info("=== ACCOUNT.INVOICE.SEND action_send ===")
return super().action_send()
def send_and_print_action(self):
_logger.info("=== ACCOUNT.INVOICE.SEND send_and_print_action ===")
return super().send_and_print_action()
def print_action(self):
_logger.info("=== ACCOUNT.INVOICE.SEND print_action ===")
return super().print_action()
@api.model
def action_send_and_print_invoices(self, invoices):
_logger.info("=== ACCOUNT.INVOICE.SEND action_send_and_print_invoices ===")
return super().action_send_and_print_invoices(invoices)