[IMP] account: Try to increment account code on duplication

Purpose
=======

Instead of adding 'copy' on the code, we could try to increment the code by 10
if possible.

Specification
=============

On an account duplication, if the code represents an Integer and if there are
no other account with the code 'code + 10', then increment the account code
by 10. Otherwise, use the default behavior (adding a 'copy' on the code label).

TaskID: 1868221
This commit is contained in:
Nicolas Bayet
2018-08-13 14:36:26 +02:00
committed by Yannick Tivisse
parent bcb9965b7b
commit db3e403962
+12 -1
View File
@@ -224,7 +224,18 @@ class AccountAccount(models.Model):
@api.returns('self', lambda value: value.id)
def copy(self, default=None):
default = dict(default or {})
default.setdefault('code', _("%s (copy)") % (self.code or ''))
if default.get('code', False):
return super(AccountAccount, self).copy(default)
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 '')
default['name'] = _("%s (copy)") % (self.name or '')
except ValueError:
default['code'] = _("%s (copy)") % (self.code or '')
default['name'] = self.name
return super(AccountAccount, self).copy(default)
@api.model