diff --git a/addons/account_peppol/models/account_edi_proxy_user.py b/addons/account_peppol/models/account_edi_proxy_user.py index 1e54d8e0e1e..9e7a14cc74c 100644 --- a/addons/account_peppol/models/account_edi_proxy_user.py +++ b/addons/account_peppol/models/account_edi_proxy_user.py @@ -82,7 +82,7 @@ class AccountEdiProxyClientUser(models.Model): message_uuids = [ message['uuid'] - for message in messages['messages'] + for message in messages.get('messages', []) if message['direction'] == 'incoming' and message['receiver'] == edi_user.edi_identification ] diff --git a/addons/account_peppol/models/res_company.py b/addons/account_peppol/models/res_company.py index 40f9fa50993..c9b21e2b30d 100644 --- a/addons/account_peppol/models/res_company.py +++ b/addons/account_peppol/models/res_company.py @@ -57,7 +57,6 @@ class ResCompany(models.Model): ('not_verified', 'Not verified'), ('sent_verification', 'Verification code sent'), ('pending', 'Pending'), - ('manually_approved', 'Approved'), ('active', 'Active'), ('rejected', 'Rejected'), ('canceled', 'Canceled'), diff --git a/addons/account_peppol/models/res_config_settings.py b/addons/account_peppol/models/res_config_settings.py index 6e845edf2e0..6ce09a2e55d 100644 --- a/addons/account_peppol/models/res_config_settings.py +++ b/addons/account_peppol/models/res_config_settings.py @@ -52,10 +52,11 @@ class ResConfigSettings(models.TransientModel): # HELPER METHODS # ------------------------------------------------------------------------- - def _call_peppol_proxy(self, endpoint, params, edi_user=None): + def _call_peppol_proxy(self, endpoint, params=None, edi_user=None): if not edi_user: edi_user = self.company_id.account_edi_proxy_client_ids[0] + params = params or {} try: response = edi_user._make_request( f"{edi_user._get_server_url()}{endpoint}", @@ -68,6 +69,12 @@ 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 # ------------------------------------------------------------------------- @@ -235,10 +242,7 @@ class ResConfigSettings(models.TransientModel): "Can't cancel registration with this status: %s", self.account_peppol_proxy_state )) - self._call_peppol_proxy( - endpoint='/api/peppol/1/cancel_peppol_registration', - params={}, - ) + self._call_peppol_proxy(endpoint='/api/peppol/1/cancel_peppol_registration') self.account_peppol_proxy_state = 'canceled' def button_reopen_peppol_registration(self): @@ -277,9 +281,25 @@ class ResConfigSettings(models.TransientModel): "Can't migrate registration with this status: %s", self.account_peppol_proxy_state )) - response = self._call_peppol_proxy( - endpoint='/api/peppol/1/migrate_peppol_registration', - params={}, - ) + 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): + """ + Deregister the edi user from Peppol network + """ + self.ensure_one() + + if self.account_peppol_proxy_state != 'active': + raise UserError(_( + "Can't deregister with this status: %s", self.account_peppol_proxy_state + )) + + self._trigger_peppol_crons() + + self._call_peppol_proxy(endpoint='/api/peppol/1/cancel_peppol_registration') + self.account_peppol_proxy_state = 'not_registered' + self.account_peppol_edi_user.unlink() 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 ea1417b9f3c..a2fbdf3eb79 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 @@ -50,21 +50,36 @@ class PeppolSettingsButtons extends Component { }); } - showConfirmation() { - const message = this.env._t("This will migrate your Peppol registration away from Odoo. You will not be able to send or receive Peppol documents in Odoo anymore."); - const confirmMessage = this.env._t("Are you sure you want to proceed?"); + showConfirmation(warning, methodName) { + const message = this.env._t(warning); + const confirmMessage = this.env._t("You will not be able to send or receive Peppol documents in Odoo anymore. Are you sure you want to proceed?"); this.dialogService.add(ConfirmationDialog, { body: markup( `