From 08b0bc2f71da39d19502795463232e2c43ae8ca9 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Mon, 13 Aug 2018 15:57:22 +0200 Subject: [PATCH] [IMP] account: Increment new account code till there's no conflict Purpose ======= Since https://github.com/odoo/odoo/commit/db3e40396232f41d86ec0c5f90e783e77f3e9510 we try to increment the account code on account duplication. Now with this commit with increment the code till there are no other account with the same code in the same company. --- addons/account/models/account.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/account/models/account.py b/addons/account/models/account.py index 80e9be668db..8d54f9ca0eb 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -238,9 +238,9 @@ class AccountAccount(models.Model): try: default['code'] = (str(int(self.code) + 10) or '') default.setdefault('name', _("%s (copy)") % (self.name or '')) - if self.env['account.account'].search([('code', '=', default['code']), - ('company_id', '=', default.get('company_id', False) or self.company_id.id)], limit=1): - default['code'] = _("%s (copy)") % (self.code or '') + while self.env['account.account'].search([('code', '=', default['code']), + ('company_id', '=', default.get('company_id', False) or self.company_id.id)], limit=1): + default['code'] = (str(int(default['code']) + 10) or '') default['name'] = _("%s (copy)") % (self.name or '') except ValueError: default['code'] = _("%s (copy)") % (self.code or '')