From f33e1ca222ab0e379eae39f7fbba10899ff5ad48 Mon Sep 17 00:00:00 2001 From: william Date: Wed, 19 Oct 2022 15:33:58 +0000 Subject: [PATCH] [FIX] account: performance of search panel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes the performance of the search panel of `account.move.line` Menu > Accounting > Accounting > Journal Items The control panel based on the accounts' roots was the issue (call to `search_panel_select_range`) Before this fix, the entire table was read through the use of a `read_group`. Since the data returned by the `read_group` is not interresting in our case, we can simply do a lateral join on an indexed column with a limit in order to improve the performances. closes odoo/odoo#107164 X-original-commit: 26dd1d9627cdd04e12c3187f0f53c0e11892a345 Signed-off-by: Quentin De Paoli Signed-off-by: William André (wan) --- addons/account/models/account_move_line.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 # -------------------------------------------------------------------------