Skip to content
Snippets Groups Projects
Commit 974caef9 authored by alt-odoo's avatar alt-odoo
Browse files

[IMP] iap: add automatic deletion of accounts without token


Since the accounts without token are useless and could create errors
afterwards, we should delete them and automatically create a new one
with a new token in case force_create is set to True.

closes odoo/odoo#98858

Signed-off-by: default avatarFlorian Daloze (fda) <fda@odoo.com>
parent 53410da3
No related branches found
No related tags found
No related merge requests found
......@@ -171,6 +171,17 @@ class IapAccount(models.Model):
('company_ids', '=', False)
]
accounts = self.search(domain, order='id desc')
accounts_without_token = accounts.filtered(lambda acc: not acc.account_token)
if accounts_without_token:
with self.pool.cursor() as cr:
# In case of a further error that will rollback the database, we should
# use a different SQL cursor to avoid undo the accounts deletion.
# Flush the pending operations to avoid a deadlock.
self.flush()
IapAccount = self.with_env(self.env(cr=cr))
IapAccount.search(domain + [('account_token', '=', False)]).unlink()
accounts = accounts - accounts_without_token
if not accounts:
with self.pool.cursor() as cr:
# Since the account did not exist yet, we will encounter a NoCreditError,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment