[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
This commit is contained in:
aliya
2024-03-22 13:02:02 +00:00
parent 4ff3638450
commit 57225048f9
@@ -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()