Fix allow_mail_archived_partner causing system notifications to send emails
This commit is contained in:
@@ -3,4 +3,4 @@ from . import mail_thread
|
|||||||
from . import res_partner
|
from . import res_partner
|
||||||
from . import mail_template
|
from . import mail_template
|
||||||
from . import mail_compose_message
|
from . import mail_compose_message
|
||||||
#from . import account_move_send
|
from . import account_move_send
|
||||||
@@ -1,14 +1,22 @@
|
|||||||
from odoo import models, api
|
from odoo import models, api
|
||||||
|
|
||||||
|
|
||||||
class AccountMoveSend(models.TransientModel):
|
class AccountMoveSendWizard(models.TransientModel):
|
||||||
_inherit = "account.move.send"
|
_inherit = "account.move.send.wizard"
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _get_default_mail_partner_ids(self, move, mail_template, mail_lang):
|
def _get_default_mail_partner_ids(self, move, mail_template, mail_lang):
|
||||||
"""
|
"""
|
||||||
The invoice 'Send by Email' wizard uses this to compute partner_ids (To:).
|
Allow archived partners when sending invoices via
|
||||||
We must disable active_test here to include archived partners.
|
the 'Send by Email' wizard.
|
||||||
"""
|
"""
|
||||||
wiz = self.with_context(active_test=False, include_archived_partners=True)
|
# Force archived partners to be visible ONLY in this context
|
||||||
return super(AccountMoveSend, wiz)._get_default_mail_partner_ids(move, mail_template, mail_lang)
|
wiz = self.with_context(
|
||||||
|
active_test=False,
|
||||||
|
include_archived_partners=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
return super(
|
||||||
|
AccountMoveSendWizard,
|
||||||
|
wiz
|
||||||
|
)._get_default_mail_partner_ids(move, mail_template, mail_lang)
|
||||||
|
|||||||
@@ -1,37 +1,33 @@
|
|||||||
from odoo import models
|
from odoo import models, api
|
||||||
|
|
||||||
|
|
||||||
class MailComposeMessage(models.TransientModel):
|
class MailComposeMessage(models.TransientModel):
|
||||||
_inherit = "mail.compose.message"
|
_inherit = "mail.compose.message"
|
||||||
|
|
||||||
def _get_default_recipients(self):
|
@api.model
|
||||||
|
def default_get(self, fields):
|
||||||
"""
|
"""
|
||||||
This is the ONLY place that fills the 'To' field in Odoo 16.
|
For sales orders and other models using generic composer.
|
||||||
We explicitly allow archived partners here for user-initiated sends.
|
|
||||||
"""
|
"""
|
||||||
recipients = super()._get_default_recipients()
|
res = super().default_get(fields)
|
||||||
|
|
||||||
model = self.env.context.get("active_model")
|
model = self.env.context.get("active_model")
|
||||||
active_ids = self.env.context.get("active_ids") or []
|
res_id = self.env.context.get("active_id")
|
||||||
|
|
||||||
if model == "account.move" and active_ids:
|
# For sales orders
|
||||||
moves = self.env["account.move"].with_context(
|
if model == "sale.order" and res_id:
|
||||||
|
order = self.env["sale.order"].with_context(
|
||||||
active_test=False
|
active_test=False
|
||||||
).browse(active_ids)
|
).browse(res_id)
|
||||||
|
|
||||||
partners = moves.mapped("partner_id").filtered(
|
if order.exists() and order.partner_id and order.partner_id.email:
|
||||||
lambda p: p.email
|
res["partner_ids"] = [(6, 0, [order.partner_id.id])]
|
||||||
)
|
|
||||||
|
|
||||||
if partners:
|
return res
|
||||||
recipients["partner_ids"] = [(6, 0, partners.ids)]
|
|
||||||
recipients["email_to"] = ", ".join(partners.mapped("email"))
|
|
||||||
|
|
||||||
return recipients
|
|
||||||
|
|
||||||
def _prepare_mail_values(self, res_ids):
|
def _prepare_mail_values(self, res_ids):
|
||||||
"""
|
"""
|
||||||
Explicit user send → allow archived partners internally.
|
For explicit user sends from sales orders.
|
||||||
"""
|
"""
|
||||||
model = self.env.context.get("active_model") or self.model
|
model = self.env.context.get("active_model") or self.model
|
||||||
|
|
||||||
@@ -46,3 +42,22 @@ class MailComposeMessage(models.TransientModel):
|
|||||||
)._prepare_mail_values(res_ids)
|
)._prepare_mail_values(res_ids)
|
||||||
|
|
||||||
return super()._prepare_mail_values(res_ids)
|
return super()._prepare_mail_values(res_ids)
|
||||||
|
|
||||||
|
def _prepare_recipient_values(self, partner):
|
||||||
|
"""
|
||||||
|
For sales orders and generic composers.
|
||||||
|
"""
|
||||||
|
model = self.env.context.get("active_model") or self.model
|
||||||
|
|
||||||
|
if (
|
||||||
|
model in ["sale.order", "account.move"]
|
||||||
|
and self.env.context.get("include_archived_partners")
|
||||||
|
and partner
|
||||||
|
):
|
||||||
|
# Use parent method with proper context
|
||||||
|
return super(
|
||||||
|
MailComposeMessage,
|
||||||
|
self.with_context(active_test=False)
|
||||||
|
)._prepare_recipient_values(partner)
|
||||||
|
|
||||||
|
return super()._prepare_recipient_values(partner)
|
||||||
Reference in New Issue
Block a user