From 34eb59f5090f87ef1b9f7dcbb7e91d14793b1b71 Mon Sep 17 00:00:00 2001
From: aliya
Date: Wed, 19 Jul 2023 17:00:21 +0000
Subject: [PATCH] [FIX] account_peppol: fix handling of migrated users
Currently, when a user requests a migration key, we set them as 'canceled' and show the migration key.
That means, they won't receive new invoices/invoice status updates.
However, the idea of the migration is that a user should be reachable at all times
and we should receive documents for them up until they are fully migrated to another service.
The solution is to keep `account_peppol_proxy_state` as `active` when they request a migration and display the migration key.
On the IAP side we will check with a cron whether they have migrated or not.
A migrated user is then archived on the IAP side.
That means that whenever we run a cron on the client side, the edi user would not be found,
so the edi user will be archived in `_make_request`.
We can then safely change the `account_peppol_proxy_state` to `not_registered`.
closes odoo/odoo#129166
Signed-off-by: Laurent Smet (las)
---
.../models/account_edi_proxy_user.py | 15 +++++++++++++++
.../account_peppol/models/res_config_settings.py | 14 ++++----------
.../res_config_settings_buttons.js | 4 ++++
.../res_config_settings_buttons.xml | 4 ++--
.../views/res_config_settings_views.xml | 8 ++++----
5 files changed, 29 insertions(+), 16 deletions(-)
diff --git a/addons/account_peppol/models/account_edi_proxy_user.py b/addons/account_peppol/models/account_edi_proxy_user.py
index 6245716666b..9106775cb10 100644
--- a/addons/account_peppol/models/account_edi_proxy_user.py
+++ b/addons/account_peppol/models/account_edi_proxy_user.py
@@ -23,6 +23,21 @@ class AccountEdiProxyClientUser(models.Model):
# HELPER METHODS
# -------------------------------------------------------------------------
+ def _make_request(self, url, params=False):
+ # extends account_edi_proxy_client to update peppol_proxy_state
+ # of archived users
+ try:
+ result = super()._make_request(url, params)
+ except AccountEdiProxyError as e:
+ if (
+ e.code == 'no_such_user'
+ and not self.active
+ and not self.company_id.account_edi_proxy_client_ids.filtered(lambda u: u.proxy_type == 'peppol')
+ ):
+ self.company_id.account_peppol_proxy_state = 'not_registered'
+ raise AccountEdiProxyError(e.code, e.message)
+ return result
+
def _get_proxy_urls(self):
urls = super()._get_proxy_urls()
urls['peppol'] = {
diff --git a/addons/account_peppol/models/res_config_settings.py b/addons/account_peppol/models/res_config_settings.py
index 6ce09a2e55d..e459781679a 100644
--- a/addons/account_peppol/models/res_config_settings.py
+++ b/addons/account_peppol/models/res_config_settings.py
@@ -69,12 +69,6 @@ class ResConfigSettings(models.TransientModel):
raise UserError(response['error'].get('message') or response['error']['data']['message'])
return response
- def _trigger_peppol_crons(self):
- # fetch all documents and message statuses before migrating/deleting
- # so that they 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()
-
# -------------------------------------------------------------------------
# COMPUTE METHODS
# -------------------------------------------------------------------------
@@ -281,10 +275,7 @@ class ResConfigSettings(models.TransientModel):
"Can't migrate registration with this status: %s", self.account_peppol_proxy_state
))
- self._trigger_peppol_crons()
-
response = self._call_peppol_proxy(endpoint='/api/peppol/1/migrate_peppol_registration')
- self.account_peppol_proxy_state = 'canceled'
self.account_peppol_migration_key = response['migration_key']
def button_deregister_peppol_participant(self):
@@ -298,7 +289,10 @@ class ResConfigSettings(models.TransientModel):
"Can't deregister with this status: %s", self.account_peppol_proxy_state
))
- self._trigger_peppol_crons()
+ # fetch all documents and message statuses before unlinking the edi user
+ # 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()
self._call_peppol_proxy(endpoint='/api/peppol/1/cancel_peppol_registration')
self.account_peppol_proxy_state = 'not_registered'
diff --git a/addons/account_peppol/static/src/components/res_config_settings_buttons/res_config_settings_buttons.js b/addons/account_peppol/static/src/components/res_config_settings_buttons/res_config_settings_buttons.js
index a2fbdf3eb79..5c44af9cbcf 100644
--- a/addons/account_peppol/static/src/components/res_config_settings_buttons/res_config_settings_buttons.js
+++ b/addons/account_peppol/static/src/components/res_config_settings_buttons/res_config_settings_buttons.js
@@ -26,6 +26,10 @@ class PeppolSettingsButtons extends Component {
return this.props.record.data.account_peppol_proxy_state;
}
+ get migrationPrepared() {
+ return this.props.record.data.account_peppol_proxy_state === "active" && Boolean(this.props.record.data.account_peppol_migration_key);
+ }
+
async _callConfigMethod(methodName, save = false) {
if (save) {
await this._save();
diff --git a/addons/account_peppol/static/src/components/res_config_settings_buttons/res_config_settings_buttons.xml b/addons/account_peppol/static/src/components/res_config_settings_buttons/res_config_settings_buttons.xml
index ff3eb9c64ce..33a33e035c6 100644
--- a/addons/account_peppol/static/src/components/res_config_settings_buttons/res_config_settings_buttons.xml
+++ b/addons/account_peppol/static/src/components/res_config_settings_buttons/res_config_settings_buttons.xml
@@ -16,7 +16,7 @@
@@ -24,7 +24,7 @@
diff --git a/addons/account_peppol/views/res_config_settings_views.xml b/addons/account_peppol/views/res_config_settings_views.xml
index d882f6c5e58..b7f5a791adf 100644
--- a/addons/account_peppol/views/res_config_settings_views.xml
+++ b/addons/account_peppol/views/res_config_settings_views.xml
@@ -141,18 +141,18 @@
- Your migration key is
+ Your migration key is:
- Your Peppol identification is
+ Your Peppol identification is: