From 57225048f976e8dc2ead2126111469e31f2f8468 Mon Sep 17 00:00:00 2001 From: aliya Date: Wed, 21 Feb 2024 17:39:30 +0100 Subject: [PATCH] [FIX] account_peppol: handle participant not ready error If the participant is not active on the IAP server, the server sends back a Participant not ready error in response without raising an error. On the client side a user sees a traceback, because we're trying to retrieve a message uuid of a non-existent peppol message: `response['messages'][i]['message_uuid']. That's because we treat that error in the try block and then proceed to the else block because technically there was no exception. This commit moves that error handling to `else` block so that such invoices get the proper error messages. Part-of: odoo/odoo#158546 --- .../wizard/account_move_send.py | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/addons/account_peppol/wizard/account_move_send.py b/addons/account_peppol/wizard/account_move_send.py index 65e2d9f270e..2be2f2a6c2f 100644 --- a/addons/account_peppol/wizard/account_move_send.py +++ b/addons/account_peppol/wizard/account_move_send.py @@ -167,25 +167,26 @@ class AccountMoveSend(models.TransientModel): f"{edi_user._get_server_url()}/api/peppol/1/send_document", params=params, ) - if response.get('error'): - # at the moment the only error that can happen here is ParticipantNotReady error - for invoice, invoice_data in invoices_data_peppol.items(): - invoice.peppol_move_state = 'error' - invoice_data['error'] = response['error']['message'] except AccountEdiProxyError as e: for invoice, invoice_data in invoices_data_peppol.items(): invoice.peppol_move_state = 'error' invoice_data['error'] = e.message else: - # the response only contains message uuids, - # so we have to rely on the order to connect peppol messages to account.move - invoices = self.env['account.move'] - for i, (invoice, invoice_data) in enumerate(invoices_data_peppol.items()): - invoice.peppol_message_uuid = response['messages'][i]['message_uuid'] - invoice.peppol_move_state = 'processing' - invoices |= invoice - log_message = _('The document has been sent to the Peppol Access Point for processing') - invoices._message_log_batch(bodies=dict((invoice.id, log_message) for invoice in invoices_data_peppol)) + if response.get('error'): + # at the moment the only error that can happen here is ParticipantNotReady error + for invoice, invoice_data in invoices_data_peppol.items(): + invoice.peppol_move_state = 'error' + invoice_data['error'] = response['error']['message'] + else: + # the response only contains message uuids, + # so we have to rely on the order to connect peppol messages to account.move + invoices = self.env['account.move'] + for message, (invoice, invoice_data) in zip(response['messages'], invoices_data_peppol.items()): + invoice.peppol_message_uuid = message['message_uuid'] + invoice.peppol_move_state = 'processing' + invoices |= invoice + log_message = _('The document has been sent to the Peppol Access Point for processing') + invoices._message_log_batch(bodies=dict((invoice.id, log_message) for invoice in invoices)) if self._can_commit(): self._cr.commit()