[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) <las@odoo.com> Signed-off-by: Aliya Tastemirova (alta) <alta@odoo.com>
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -158,13 +158,6 @@
|
||||
string="Cancel registration"
|
||||
class="btn btn-secondary"/>
|
||||
</div>
|
||||
<div class="mt-3"
|
||||
invisible="account_peppol_proxy_state != 'canceled' or account_peppol_migration_key">
|
||||
<button name="button_reopen_peppol_registration"
|
||||
type="object"
|
||||
string="Retry registration"
|
||||
class="btn btn-secondary"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user