From 4d6e55af0ff5da068a0c3444e08f8b11c316c202 Mon Sep 17 00:00:00 2001 From: Kristof Bernaert Date: Mon, 26 Jan 2026 03:43:22 +0100 Subject: [PATCH] Fix allow_mail_archived_partner causing system notifications to send emails --- .../models/account_move_send.py | 64 ++----------------- 1 file changed, 5 insertions(+), 59 deletions(-) diff --git a/allow_mail_archived_partner/models/account_move_send.py b/allow_mail_archived_partner/models/account_move_send.py index a664451..50969ad 100755 --- a/allow_mail_archived_partner/models/account_move_send.py +++ b/allow_mail_archived_partner/models/account_move_send.py @@ -18,56 +18,27 @@ class AccountInvoiceSend(models.TransientModel): @api.model def default_get(self, fields): - _logger.info("=== ACCOUNT.INVOICE.SEND DEFAULT_GET ===") - + """ + Simply add archived partners to the wizard. + """ res = super().default_get(fields) - _logger.info(f"Initial result: {res}") active_ids = self.env.context.get('active_ids', []) - _logger.info(f"Active IDs: {active_ids}") - if active_ids: - # Find invoices with archived partners allowed moves = self.env['account.move'].with_context( active_test=False ).browse(active_ids) partners = moves.mapped('partner_id').filtered(lambda p: p.email) - _logger.info(f"Found partners: {partners.ids}") - if partners: - # Set BOTH fields res['partner_ids'] = [(6, 0, partners.ids)] - res['email_to'] = ",".join(partners.mapped('email')) - _logger.info(f"Set partner_ids: {res['partner_ids']}") - _logger.info(f"Set email_to: {res['email_to']}") return res def action_send_and_print(self): """ - Ensure email_to is set before sending. + Just pass context - let parent handle everything. """ - _logger.info("=== ACCOUNT.INVOICE.SEND action_send_and_print ===") - _logger.info(f"Wizard ID: {self.id}") - _logger.info(f"Partner IDs: {self.partner_ids.ids}") - _logger.info(f"Current email_to: {self.email_to}") - - # Ensure email_to is set from partner_ids - if self.partner_ids and not self.email_to: - emails = [p.email for p in self.partner_ids if p.email] - if emails: - self.email_to = ",".join(emails) - _logger.info(f"Updated email_to: {self.email_to}") - - # Also ensure partner_ids are written to the record - if self.partner_ids: - _logger.info(f"Writing partner_ids to record") - self.write({'partner_ids': [(6, 0, self.partner_ids.ids)]}) - - _logger.info(f"Final context before send: {dict(self.env.context)}") - - # Call parent with context return super( AccountInvoiceSend, self.with_context( @@ -77,29 +48,4 @@ class AccountInvoiceSend(models.TransientModel): force_email=True, mark_invoice_as_sent=True, ) - ).action_send_and_print() - - def write(self, vals): - """ - Ensure when partner_ids are written, email_to is also updated. - """ - _logger.info("=== ACCOUNT.INVOICE.SEND WRITE ===") - _logger.info(f"Write vals keys: {vals.keys()}") - - if 'partner_ids' in vals and not vals.get('email_to'): - # Get partner emails - partner_ids = vals['partner_ids'][0][2] if vals['partner_ids'] else [] - _logger.info(f"Partner IDs in write: {partner_ids}") - - if partner_ids: - partners = self.env['res.partner'].with_context( - active_test=False - ).browse(partner_ids) - emails = [p.email for p in partners if p.email] - if emails: - vals['email_to'] = ",".join(emails) - _logger.info(f"Auto-updated email_to in write: {vals['email_to']}") - - result = super().write(vals) - _logger.info(f"Write completed") - return result \ No newline at end of file + ).action_send_and_print() \ No newline at end of file