From 37f7f7b29ae1b17c8d21cd3ed316ab246ee51d04 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Wed, 23 Jan 2019 22:07:46 +0000 Subject: [PATCH] [FIX] account: speedup the creation of the chart of accounts closes odoo/odoo#30493 --- addons/account/models/account.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/addons/account/models/account.py b/addons/account/models/account.py index d7613478ce6..d0acbc380c0 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -67,12 +67,11 @@ class AccountAccount(models.Model): @api.constrains('user_type_id') def _check_user_type_id(self): data_unaffected_earnings = self.env.ref('account.data_unaffected_earnings') - for company in self.mapped('company_id'): - account_unaffected_earnings = self.search([ - ('company_id', '=', company.id), - ('user_type_id', '=', data_unaffected_earnings.id), - ]) - if len(account_unaffected_earnings) >= 2: + result = self.read_group([('user_type_id', '=', data_unaffected_earnings.id)], ['company_id'], ['company_id']) + for res in result: + if res.get('company_id_count', 0) >= 2: + account_unaffected_earnings = self.search([('company_id', '=', res['company_id'][0]), + ('user_type_id', '=', data_unaffected_earnings.id)]) raise ValidationError(_('You cannot have more than one account with "Current Year Earnings" as type. (accounts: %s)') % [a.code for a in account_unaffected_earnings]) name = fields.Char(required=True, index=True)