diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index af7f209c0d5..64c9eef2044 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -1533,6 +1533,25 @@ class AccountMoveLine(models.Model): line._copy_data_extend_business_fields(values) return data_list + def _search_panel_domain_image(self, field_name, domain, set_count=False, limit=False): + if field_name != 'account_root_id' or set_count: + return super()._search_panel_domain_image(field_name, domain, set_count, limit) + + # Override in order to not read the complete move line table and use the index instead + query = self._search(domain, limit=1) + query.order = None + query.add_where('account.id = account_move_line.account_id') + query_str, query_param = query.select() + self.env.cr.execute(f""" + SELECT account.root_id + FROM account_account account, + LATERAL ({query_str}) line + """, query_param) + return { + root.id: {'id': root.id, 'display_name': root.display_name} + for root in self.env['account.root'].browse(id for [id] in self.env.cr.fetchall()) + } + # ------------------------------------------------------------------------- # TRACKING METHODS # -------------------------------------------------------------------------