Fix allow_mail_archived_partner causing system notifications to send emails

This commit is contained in:
Kristof Bernaert
2026-01-26 01:33:32 +01:00
parent c5a92d81df
commit a0c3704121
2 changed files with 61 additions and 54 deletions
@@ -4,11 +4,39 @@ from odoo import models, api
class AccountInvoiceSend(models.TransientModel):
_inherit = "account.invoice.send"
@api.model
def default_get(self, fields):
"""
Override default_get to pre-fill archived partners.
This is often called BEFORE _get_default_mail_partner_ids.
"""
res = super().default_get(fields)
# Check if we're in the right context
active_model = self.env.context.get('active_model')
active_ids = self.env.context.get('active_ids', [])
if active_model == 'account.move' and active_ids:
# Get the moves with archived partners allowed
moves = self.env['account.move'].with_context(
active_test=False
).browse(active_ids)
# Collect all unique partners from the moves
partner_ids = set()
for move in moves:
if move.partner_id and move.partner_id.email:
partner_ids.add(move.partner_id.id)
if partner_ids:
res['partner_ids'] = [(6, 0, list(partner_ids))]
return res
@api.model
def _get_default_mail_partner_ids(self, move, mail_template, mail_lang):
"""
Allow archived partners when sending invoices via
the 'Send by Email' wizard.
Also fix this method to include archived partners.
"""
wiz = self.with_context(
active_test=False,
@@ -18,3 +46,16 @@ class AccountInvoiceSend(models.TransientModel):
AccountInvoiceSend,
wiz
)._get_default_mail_partner_ids(move, mail_template, mail_lang)
def _get_mail_composer_values(self, move, template, partner_ids):
"""
Ensure context is passed to mail composer.
"""
return super(
AccountInvoiceSend,
self.with_context(
active_test=False,
include_archived_partners=True,
mail_notify_force=True,
)
)._get_mail_composer_values(move, template, partner_ids)