Fix allow_mail_archived_partner causing system notifications to send emails
This commit is contained in:
@@ -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"
|
||||||
|
|
||||||
# OVERRIDE THE FIELD DEFINITION to remove domain filter
|
# OVERRIDE THE FIELD DEFINITION
|
||||||
partner_ids = fields.Many2many(
|
partner_ids = fields.Many2many(
|
||||||
'res.partner',
|
'res.partner',
|
||||||
string='Recipients',
|
string='Recipients',
|
||||||
@@ -18,22 +18,13 @@ class AccountInvoiceSend(models.TransientModel):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def default_get(self, fields):
|
def default_get(self, fields):
|
||||||
"""
|
|
||||||
Pre-fill invoice email wizard with archived partners.
|
|
||||||
"""
|
|
||||||
_logger.info("=== ACCOUNT.INVOICE.SEND DEFAULT_GET ===")
|
_logger.info("=== ACCOUNT.INVOICE.SEND DEFAULT_GET ===")
|
||||||
_logger.info(f"Fields requested: {fields}")
|
|
||||||
_logger.info(f"Context: {dict(self.env.context)}")
|
|
||||||
|
|
||||||
# Get default result first
|
|
||||||
res = super().default_get(fields)
|
res = super().default_get(fields)
|
||||||
_logger.info(f"Super result partner_ids: {res.get('partner_ids')}")
|
|
||||||
|
|
||||||
active_ids = self.env.context.get('active_ids', [])
|
active_ids = self.env.context.get('active_ids', [])
|
||||||
_logger.info(f"Active IDs: {active_ids}")
|
|
||||||
|
|
||||||
if active_ids:
|
if active_ids:
|
||||||
# Find invoices with archived partners allowed
|
|
||||||
moves = self.env['account.move'].with_context(
|
moves = self.env['account.move'].with_context(
|
||||||
active_test=False
|
active_test=False
|
||||||
).browse(active_ids)
|
).browse(active_ids)
|
||||||
@@ -42,42 +33,18 @@ class AccountInvoiceSend(models.TransientModel):
|
|||||||
for move in moves:
|
for move in moves:
|
||||||
if move.partner_id:
|
if move.partner_id:
|
||||||
partner_ids.append(move.partner_id.id)
|
partner_ids.append(move.partner_id.id)
|
||||||
_logger.info(f"Found partner {move.partner_id.id} (active={move.partner_id.active}) for invoice {move.id}")
|
|
||||||
|
|
||||||
if partner_ids:
|
if partner_ids:
|
||||||
res['partner_ids'] = [(6, 0, partner_ids)]
|
res['partner_ids'] = [(6, 0, partner_ids)]
|
||||||
_logger.info(f"SET partner_ids: {res['partner_ids']}")
|
_logger.info(f"SET partner_ids: {res['partner_ids']}")
|
||||||
else:
|
|
||||||
_logger.info("No partners found for invoices")
|
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _get_composer_values(self, res_ids, template):
|
|
||||||
"""
|
|
||||||
Pass context to mail composer to allow archived partners.
|
|
||||||
"""
|
|
||||||
_logger.info("=== ACCOUNT.INVOICE.SEND _get_composer_values ===")
|
|
||||||
_logger.info(f"Passing context to allow archived partners")
|
|
||||||
return super(
|
|
||||||
AccountInvoiceSend,
|
|
||||||
self.with_context(
|
|
||||||
active_test=False,
|
|
||||||
include_archived_partners=True,
|
|
||||||
mail_notify_force=True,
|
|
||||||
)
|
|
||||||
)._get_composer_values(res_ids, template)
|
|
||||||
|
|
||||||
def action_send_and_print(self):
|
def action_send_and_print(self):
|
||||||
"""
|
|
||||||
Override send action to add logging and ensure context is passed.
|
|
||||||
"""
|
|
||||||
_logger.info("=== ACCOUNT.INVOICE.SEND action_send_and_print ===")
|
_logger.info("=== ACCOUNT.INVOICE.SEND action_send_and_print ===")
|
||||||
_logger.info(f"Wizard ID: {self.id}")
|
_logger.info(f"Wizard ID: {self.id}, Partners: {self.partner_ids.ids}")
|
||||||
_logger.info(f"Partner IDs: {self.partner_ids.ids}")
|
|
||||||
_logger.info(f"Context before: {dict(self.env.context)}")
|
|
||||||
|
|
||||||
# Ensure context is passed when calling action
|
return super(
|
||||||
result = super(
|
|
||||||
AccountInvoiceSend,
|
AccountInvoiceSend,
|
||||||
self.with_context(
|
self.with_context(
|
||||||
active_test=False,
|
active_test=False,
|
||||||
@@ -88,5 +55,20 @@ class AccountInvoiceSend(models.TransientModel):
|
|||||||
)
|
)
|
||||||
).action_send_and_print()
|
).action_send_and_print()
|
||||||
|
|
||||||
_logger.info("Email send action completed")
|
# LOG ALL POSSIBLE ACTIONS
|
||||||
return result
|
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)
|
||||||
Reference in New Issue
Block a user