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()