From c50e82c127082f5202cced4bf30bc166bdb9efca Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Thu, 31 Jan 2019 09:20:15 +0000 Subject: [PATCH] [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 --- addons/account/models/company.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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,