From f646aaeb655c4aa3e328c5f209a569ad7238ddc2 Mon Sep 17 00:00:00 2001 From: Kristof Bernaert Date: Mon, 26 Jan 2026 04:09:02 +0100 Subject: [PATCH] Fix allow_mail_archived_partner causing system notifications to send emails --- .../models/account_move_send.py | 11 ++-------- .../models/mail_thread.py | 22 +++++++++++++++---- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/allow_mail_archived_partner/models/account_move_send.py b/allow_mail_archived_partner/models/account_move_send.py index d8f4c83..a760faa 100755 --- a/allow_mail_archived_partner/models/account_move_send.py +++ b/allow_mail_archived_partner/models/account_move_send.py @@ -38,16 +38,9 @@ class AccountInvoiceSend(models.TransientModel): def action_send_and_print(self): _logger.error("🔥🔥🔥 ACCOUNT.INVOICE.SEND action_send_and_print CALLED 🔥🔥🔥") _logger.error(f"🔥 Wizard ID: {self.id}") - _logger.error(f"🔥 Partner IDs: {self.partner_ids.ids}") - _logger.error(f"🔥 Current context: {dict(self.env.context)}") - - # CRITICAL: Get the actual partner email for logging - if self.partner_ids: - for partner in self.partner_ids: - _logger.error(f"🔥 Wizard partner: {partner.id} - {partner.name}, active={partner.active}, email={partner.email}") + _logger.error(f"🔥 Partner IDs: {self.partner_ids.ids}") # This returns a list of IDs # Call parent with context AND ensure partner_ids are passed - # We need to pass partner_ids to the message_post call return super( AccountInvoiceSend, self.with_context( @@ -56,7 +49,7 @@ class AccountInvoiceSend(models.TransientModel): mail_notify_force=True, force_email=True, mark_invoice_as_sent=True, - # Add partner_ids to context so mail_thread can access them + # Pass simple list of IDs, NOT ORM tuple format invoice_partner_ids=self.partner_ids.ids if self.partner_ids else [], ) ).action_send_and_print() diff --git a/allow_mail_archived_partner/models/mail_thread.py b/allow_mail_archived_partner/models/mail_thread.py index d50897a..f33b429 100755 --- a/allow_mail_archived_partner/models/mail_thread.py +++ b/allow_mail_archived_partner/models/mail_thread.py @@ -121,7 +121,7 @@ class MailThread(models.AbstractModel): def message_post(self, **kwargs): """ - Override to ensure partner_ids are passed from context when empty. + Override to ensure partner_ids are passed correctly. """ _logger.error("🔥🔥🔥 MailThread.message_post CALLED 🔥🔥🔥") _logger.error(f"🔥 Model: {self._name}") @@ -133,14 +133,28 @@ class MailThread(models.AbstractModel): context_partner_ids = self.env.context.get('invoice_partner_ids', []) if context_partner_ids and not kwargs.get('partner_ids'): _logger.error(f"🔥 Using partner_ids from context: {context_partner_ids}") - kwargs['partner_ids'] = [(6, 0, context_partner_ids)] + # Convert to simple list of IDs, NOT ORM tuple format + kwargs['partner_ids'] = context_partner_ids # Also check for other sources of partner_ids if not kwargs.get('partner_ids'): # Try to get from the record itself - if self and hasattr(self, 'partner_id'): + if self and hasattr(self, 'partner_id') and self.partner_id: _logger.error(f"🔥 Getting partner_id from record: {self.partner_id.id}") - kwargs['partner_ids'] = [(6, 0, [self.partner_id.id])] + kwargs['partner_ids'] = [self.partner_id.id] + + # Convert ORM tuple format to simple list if needed + if kwargs.get('partner_ids') and isinstance(kwargs['partner_ids'], list): + # Check if it's in ORM format [(6, 0, [id1, id2])] + if (len(kwargs['partner_ids']) == 1 and + isinstance(kwargs['partner_ids'][0], (list, tuple)) and + len(kwargs['partner_ids'][0]) == 3 and + kwargs['partner_ids'][0][0] == 6): + + # Extract IDs from ORM format + partner_ids = kwargs['partner_ids'][0][2] + _logger.error(f"🔥 Converting ORM format to simple list: {kwargs['partner_ids']} -> {partner_ids}") + kwargs['partner_ids'] = partner_ids _logger.error(f"🔥 Final partner_ids being passed: {kwargs.get('partner_ids', [])}")