summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabien Pinckaers <fp@openerp.com>2019-01-31 09:20:15 +0000
committerNicolas Martinelli <nim@odoo.com>2019-01-31 09:23:54 +0000
commitc50e82c127082f5202cced4bf30bc166bdb9efca (patch)
treef796f6e39ad61f29b314f27d75c7375171b70942
parentc4d222677f4c5a34582d8d5b8b93d94ed873b5fa (diff)
[FIX] account: Undistributed Profits/Losses
If no Undistributed Profits/Losses account can be found, Odoo tries to create one with number '999999'. However, such an account number might have been created manually by a user. In this case, the account creation fails. opw-1932701 closes odoo/odoo#30719
-rw-r--r--addons/account/models/company.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/addons/account/models/company.py b/addons/account/models/company.py
index 5ea0db1cd95..f2efe950361 100644
--- a/addons/account/models/company.py
+++ b/addons/account/models/company.py
@@ -381,8 +381,13 @@ Best Regards,'''))
('user_type_id', '=', unaffected_earnings_type.id)])
if account:
return account[0]
+ # Do not assume '999999' doesn't exist since the user might have created such an account
+ # manually.
+ code = 999999
+ while self.env['account.account'].search([('code', '=', str(code)), ('company_id', '=', self.id)]):
+ code -= 1
return self.env['account.account'].create({
- 'code': '999999',
+ 'code': str(code),
'name': _('Undistributed Profits/Losses'),
'user_type_id': unaffected_earnings_type.id,
'company_id': self.id,