From 13960a67253d1b1f70bb1b4944d240cff9c338b3 Mon Sep 17 00:00:00 2001 From: aliya Date: Wed, 7 Jun 2023 11:01:39 +0000 Subject: [PATCH] [FIX] account_peppol: fix several bugs This commit fixes small bugs: - Sometimes we don't receive the attachments' file name from the proxy. Instead of saving the attachment with `False` as the filename, we should default to something. - If for some reason the participant's status is changed on the proxy server after documents have been sent, retrieving the message status will traceback. This commit adds a condition to catch this case. - Currently, the participant status is only updated if their application is pending. But it can happen that they are approved but not registered to the SMP. Participant status should be checked for approved edi users too. closes odoo/odoo#125437 X-original-commit: a70a388cc6cba1f0f440ca7b9dafe9b6ef6593f4 Signed-off-by: Laurent Smet --- addons/account_peppol/i18n/account_peppol.pot | 7 +++++++ .../models/account_edi_proxy_user.py | 17 +++++++++++++---- .../account_peppol/views/res_partner_views.xml | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/addons/account_peppol/i18n/account_peppol.pot b/addons/account_peppol/i18n/account_peppol.pot index 4d170a8f7b3..c1c2c17dc44 100644 --- a/addons/account_peppol/i18n/account_peppol.pot +++ b/addons/account_peppol/i18n/account_peppol.pot @@ -332,6 +332,13 @@ msgstr "" msgid "Peppol error: %s" msgstr "" +#. module: account_peppol +#. odoo-python +#: code:addons/account_peppol/models/account_edi_proxy_user.py:0 +#, python-format +msgid "Peppol status update: %s" +msgstr "" + #. module: account_peppol #. odoo-python #: code:addons/account_peppol/models/account_edi_proxy_user.py:0 diff --git a/addons/account_peppol/models/account_edi_proxy_user.py b/addons/account_peppol/models/account_edi_proxy_user.py index e2a434b700b..5c9b6dc8902 100644 --- a/addons/account_peppol/models/account_edi_proxy_user.py +++ b/addons/account_peppol/models/account_edi_proxy_user.py @@ -100,7 +100,7 @@ class AccountEdiProxyClientUser(models.Model): enc_key = content["enc_key"] document_content = content["document"] - filename = content["filename"] + filename = content["filename"] or 'attachment' # default to attachment, which should not usually happen partner_endpoint = content["accounting_supplier_party"] decoded_document = edi_user._decrypt_data(document_content, enc_key) @@ -180,13 +180,22 @@ class AccountEdiProxyClientUser(models.Model): ) for uuid, content in messages_to_process.items(): + if uuid == 'error': + # this rare edge case can happen if the participant is not active on the proxy side + # in this case we can't get information about the invoices + edi_user_moves.peppol_move_state = 'error' + log_message = _("Peppol error: %s", content['message']) + edi_user_moves._message_log_batch(bodies=dict((move.id, log_message) for move in edi_user_moves)) + continue + move = message_uuids[uuid] if content.get('error'): move.peppol_move_state = 'error' - move._message_log(body=_('Peppol error: %s', content['error']['message'])) + move._message_log(body=_("Peppol error: %s", content['error']['message'])) continue + move.peppol_move_state = content['state'] - move._message_log(body=_('Peppol update: %s', content['state'])) + move._message_log(body=_('Peppol status update: %s', content['state'])) if message_uuids: edi_user._make_request( @@ -196,7 +205,7 @@ class AccountEdiProxyClientUser(models.Model): def _cron_peppol_get_participant_status(self): edi_users = self.env['account_edi_proxy_client.user'].search( - [('company_id.account_peppol_proxy_state', '=', 'pending')]) + [('company_id.account_peppol_proxy_state', 'in', ('pending', 'manually_approved'))]) for edi_user in edi_users: try: diff --git a/addons/account_peppol/views/res_partner_views.xml b/addons/account_peppol/views/res_partner_views.xml index 38408f741d0..c31fcad4026 100644 --- a/addons/account_peppol/views/res_partner_views.xml +++ b/addons/account_peppol/views/res_partner_views.xml @@ -25,7 +25,7 @@