diff --git a/allow_mail_archived_partner/models/account_move_send.py b/allow_mail_archived_partner/models/account_move_send.py index 14a9727..905cb7e 100755 --- a/allow_mail_archived_partner/models/account_move_send.py +++ b/allow_mail_archived_partner/models/account_move_send.py @@ -12,8 +12,7 @@ class AccountInvoiceSend(models.TransientModel): 'res.partner', string='Recipients', help='Contacts of the invoice that will receive the email.', - # REMOVE any domain that filters by active=True - context={'active_test': False}, # Allow archived in searches + context={'active_test': False}, check_company=True, ) @@ -22,13 +21,16 @@ class AccountInvoiceSend(models.TransientModel): """ Pre-fill invoice email wizard with archived partners. """ - _logger.debug("=== 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) - _logger.debug(f"Super result partner_ids: {res.get('partner_ids')}") + _logger.info(f"Super result partner_ids: {res.get('partner_ids')}") active_ids = self.env.context.get('active_ids', []) - _logger.debug(f"Active IDs: {active_ids}") + _logger.info(f"Active IDs: {active_ids}") if active_ids: # Find invoices with archived partners allowed @@ -40,11 +42,13 @@ class AccountInvoiceSend(models.TransientModel): for move in moves: if move.partner_id: partner_ids.append(move.partner_id.id) - _logger.debug(f"Found partner {move.partner_id.id} for invoice {move.id}") + _logger.info(f"Found partner {move.partner_id.id} (active={move.partner_id.active}) for invoice {move.id}") if partner_ids: res['partner_ids'] = [(6, 0, partner_ids)] - _logger.debug(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 @@ -52,14 +56,13 @@ class AccountInvoiceSend(models.TransientModel): """ Pass context to mail composer to allow archived partners. """ - _logger.debug("=== _get_composer_values ===") - _logger.debug(f"Passing context to allow archived partners") - # FIX: Changed include_archived_partner to include_archived_partners (plural) + _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, # FIXED: plural 's' + include_archived_partners=True, mail_notify_force=True, ) )._get_composer_values(res_ids, template) @@ -68,32 +71,13 @@ class AccountInvoiceSend(models.TransientModel): """ Override send action to add logging and ensure context is passed. """ - _logger.debug("=== ACCOUNT.INVOICE.SEND action_send_and_print ===") - _logger.debug(f"Context before send: {dict(self.env.context)}") - _logger.debug(f"Partner IDs: {self.partner_ids.ids}") + _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"Context before: {dict(self.env.context)}") # Ensure context is passed when calling action result = super( - AccountInvoiceSend, - self.with_context( - active_test=False, - include_archived_partners=True, - mail_notify_force=True, - force_email=True, # Ensure mail_thread.py recognizes this - mark_invoice_as_sent=True, # Ensure mail_thread.py recognizes this - ) - ).action_send_and_print() - - _logger.debug("Email send action completed") - return result - - # Also override the regular send action if it exists - def action_send(self): - """ - Override send action (without print) to ensure context. - """ - _logger.debug("=== ACCOUNT.INVOICE.SEND action_send ===") - return super( AccountInvoiceSend, self.with_context( active_test=False, @@ -102,4 +86,7 @@ class AccountInvoiceSend(models.TransientModel): force_email=True, mark_invoice_as_sent=True, ) - ).action_send() \ No newline at end of file + ).action_send_and_print() + + _logger.info("Email send action completed") + return result \ No newline at end of file