From c2ef1269485ee6a8f19b85298eaa6a64d933297a Mon Sep 17 00:00:00 2001 From: aliya Date: Thu, 12 Oct 2023 17:23:25 +0200 Subject: [PATCH] [FIX] account_peppol: remove inactive canceled edi users - If an edi user needs cancellation before they were registered on the SMP, we should let them cancel and return to the very first step. We don't need the edi user anymore in that case (no messages could've been received or sent) so we can safely unlink. Same is done on the proxy side. - With that, reopening the registration is no longer needed, as we currently don't let users reopen their application when they're rejected. closes odoo/odoo#139718 Signed-off-by: Laurent Smet (las) Signed-off-by: Aliya Tastemirova (alta) --- addons/account_peppol/i18n/account_peppol.pot | 9 +++++ .../models/account_edi_proxy_user.py | 7 ++-- .../models/res_config_settings.py | 35 ++++++------------- .../views/res_config_settings_views.xml | 7 ---- 4 files changed, 23 insertions(+), 35 deletions(-) diff --git a/addons/account_peppol/i18n/account_peppol.pot b/addons/account_peppol/i18n/account_peppol.pot index 68d1526a466..379fbf24a14 100644 --- a/addons/account_peppol/i18n/account_peppol.pot +++ b/addons/account_peppol/i18n/account_peppol.pot @@ -79,6 +79,15 @@ msgid "" "e-invoices." msgstr "" +#. module: account_peppol +#. odoo-python +#: code:addons/account_peppol/models/res_config_settings.py:0 +#, python-format +msgid "" +"Can't cancel an active registration. Please request a migration or " +"deregister instead." +msgstr "" + #. module: account_peppol #: model_terms:ir.ui.view,arch_db:account_peppol.account_peppol_view_move_form msgid "Cancel PEPPOL" diff --git a/addons/account_peppol/models/account_edi_proxy_user.py b/addons/account_peppol/models/account_edi_proxy_user.py index 3aaad519ccb..7efaf168c15 100644 --- a/addons/account_peppol/models/account_edi_proxy_user.py +++ b/addons/account_peppol/models/account_edi_proxy_user.py @@ -216,10 +216,11 @@ 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')]) + edi_users = self.search([('company_id.account_peppol_proxy_state', '=', 'pending')]) + edi_users._peppol_get_participant_status() - for edi_user in edi_users: + def _peppol_get_participant_status(self): + for edi_user in self: try: proxy_user = edi_user._make_request( f"{edi_user._get_server_url()}/api/peppol/1/participant_status") diff --git a/addons/account_peppol/models/res_config_settings.py b/addons/account_peppol/models/res_config_settings.py index 4a24566dceb..a1312768202 100644 --- a/addons/account_peppol/models/res_config_settings.py +++ b/addons/account_peppol/models/res_config_settings.py @@ -233,15 +233,20 @@ class ResConfigSettings(models.TransientModel): Sets the peppol registration to canceled - If the user is active on the SMP, we can't just cancel it. They have to request a migration key using the `button_migrate_peppol_registration` action + or deregister. - 'not_registered', 'rejected', 'canceled' proxy states mean that canceling the registration makes no sense, so we don't do it - Calls the IAP server first before setting the state as canceled on the client side, in case they've been activated on the IAP side in the meantime """ self.ensure_one() + # check if the participant has been already registered + self.account_peppol_edi_user._peppol_get_participant_status() + if not tools.config['test_enable'] and not modules.module.current_test: + self.env.cr.commit() if self.account_peppol_proxy_state == 'active': - raise UserError(_("Can't cancel an active registration. Please request a migration instead.")) + raise UserError(_("Can't cancel an active registration. Please request a migration or deregister instead.")) if self.account_peppol_proxy_state in {'not_registered', 'rejected', 'canceled'}: raise UserError(_( @@ -249,30 +254,8 @@ class ResConfigSettings(models.TransientModel): )) self._call_peppol_proxy(endpoint='/api/peppol/1/cancel_peppol_registration') - self.account_peppol_proxy_state = 'canceled' - - def button_reopen_peppol_registration(self): - """ - Reopen a canceled or rejected peppol application. - This means that the EDI user already exists in the DB and on the IAP proxy. - So, reopening resets the user to the stage after validating (not_verified). - The user then needs to verify their phone number, even if they verified before canceling. - """ - self.ensure_one() - - if self.account_peppol_proxy_state in {'rejected', 'canceled'}: - params = { - 'update_data': { - 'peppol_state': 'draft', - } - } - - self._call_peppol_proxy( - endpoint='/api/peppol/1/update_user', - params=params, - ) - - self.account_peppol_proxy_state = 'not_verified' + self.account_peppol_proxy_state = 'not_registered' + self.account_peppol_edi_user.unlink() @handle_demo def button_migrate_peppol_registration(self): @@ -307,6 +290,8 @@ class ResConfigSettings(models.TransientModel): # so that the invoices are acknowledged self.env['account_edi_proxy_client.user']._cron_peppol_get_message_status() self.env['account_edi_proxy_client.user']._cron_peppol_get_new_documents() + if not tools.config['test_enable'] and not modules.module.current_test: + self.env.cr.commit() self._call_peppol_proxy(endpoint='/api/peppol/1/cancel_peppol_registration') self.account_peppol_proxy_state = 'not_registered' diff --git a/addons/account_peppol/views/res_config_settings_views.xml b/addons/account_peppol/views/res_config_settings_views.xml index d98023a8265..746b5056bdd 100644 --- a/addons/account_peppol/views/res_config_settings_views.xml +++ b/addons/account_peppol/views/res_config_settings_views.xml @@ -158,13 +158,6 @@ string="Cancel registration" class="btn btn-secondary"/> -
-