[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) <las@odoo.com>
This commit is contained in:
@@ -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'] = {
|
||||
|
||||
@@ -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'
|
||||
|
||||
+4
@@ -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();
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@
|
||||
<button type="button"
|
||||
class="btn btn-secondary me-1"
|
||||
t-on-click="migrate"
|
||||
t-if="proxyState === 'active'">
|
||||
t-if="proxyState === 'active' and migrationPrepared === false">
|
||||
Migrate registration to another service
|
||||
</button>
|
||||
</div>
|
||||
@@ -24,7 +24,7 @@
|
||||
<button type="button"
|
||||
class="btn btn-secondary me-1"
|
||||
t-on-click="deregister"
|
||||
t-if="proxyState === 'active'">
|
||||
t-if="proxyState === 'active' and migrationPrepared === false">
|
||||
Deregister from Peppol
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -141,18 +141,18 @@
|
||||
</p>
|
||||
</div>
|
||||
<div attrs="{'invisible': ['|',
|
||||
('account_peppol_proxy_state', '!=', 'canceled'),
|
||||
('account_peppol_proxy_state', '!=', 'active'),
|
||||
('account_peppol_migration_key', '=', False)]}">
|
||||
Your migration key is
|
||||
Your migration key is:
|
||||
<field name="account_peppol_migration_key"
|
||||
nolabel="1"
|
||||
attrs="{'readonly': [
|
||||
('account_peppol_proxy_state', '=', 'canceled'),
|
||||
('account_peppol_proxy_state', '=', 'active'),
|
||||
('account_peppol_migration_key', '!=', False)
|
||||
]}"/>
|
||||
</div>
|
||||
<div attrs="{'invisible': [('account_peppol_proxy_state', '!=', 'active')]}">
|
||||
Your Peppol identification is
|
||||
Your Peppol identification is:
|
||||
<field name="account_peppol_edi_identification"
|
||||
nolabel="1"/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user