Fix allow_mail_archived_partner causing system notifications to send emails

This commit is contained in:
Kristof Bernaert
2026-01-26 03:34:02 +01:00
parent 24fedec736
commit 4e4a41183a
@@ -7,7 +7,7 @@ from odoo import models, api, fields
class AccountInvoiceSend(models.TransientModel): class AccountInvoiceSend(models.TransientModel):
_inherit = "account.invoice.send" _inherit = "account.invoice.send"
# Allow archived partners to stay visible in the wizard # Allow archived partners to remain selectable
partner_ids = fields.Many2many( partner_ids = fields.Many2many(
'res.partner', 'res.partner',
string='Recipients', string='Recipients',
@@ -34,17 +34,19 @@ class AccountInvoiceSend(models.TransientModel):
def action_send_and_print(self): def action_send_and_print(self):
""" """
Explicitly rebuild recipients from partner_ids to avoid Explicitly set email_to on the wizard record.
Odoo silently skipping send when archived partners are used. This is REQUIRED for account.invoice.send.
""" """
self.ensure_one() self.ensure_one()
# Build email_to explicitly
emails = [p.email for p in self.partner_ids if p.email] emails = [p.email for p in self.partner_ids if p.email]
if not emails: if not emails:
_logger.warning("No recipient emails found; skipping send.") _logger.warning("No recipient emails found; skipping send.")
return {'type': 'ir.actions.act_window_close'} return {'type': 'ir.actions.act_window_close'}
# 🔥 THIS is the critical line
self.email_to = ",".join(emails)
return super( return super(
AccountInvoiceSend, AccountInvoiceSend,
self.with_context( self.with_context(
@@ -53,6 +55,5 @@ class AccountInvoiceSend(models.TransientModel):
mail_notify_force=True, mail_notify_force=True,
force_email=True, force_email=True,
mark_invoice_as_sent=True, mark_invoice_as_sent=True,
email_to=",".join(emails),
) )
).action_send_and_print() ).action_send_and_print()