Fix allow_mail_archived_partner causing system notifications to send emails

This commit is contained in:
Kristof Bernaert
2026-01-26 01:50:07 +01:00
parent a0c3704121
commit 7d9e08fbe5
3 changed files with 101 additions and 81 deletions
@@ -1,3 +1,4 @@
# account_move_send.py
from odoo import models, api
@@ -7,55 +8,24 @@ class AccountInvoiceSend(models.TransientModel):
@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.
Pre-fill invoice email wizard with archived partner.
"""
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(
if active_ids:
# Find invoices WITH archived partners
invoices = 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)
partner_ids = []
for inv in invoices:
if inv.partner_id:
partner_ids.append(inv.partner_id.id)
if partner_ids:
res['partner_ids'] = [(6, 0, list(partner_ids))]
res['partner_ids'] = [(6, 0, partner_ids)]
return res
@api.model
def _get_default_mail_partner_ids(self, move, mail_template, mail_lang):
"""
Also fix this method to include archived partners.
"""
wiz = self.with_context(
active_test=False,
include_archived_partners=True,
)
return super(
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)
return res