[FIX] account: performance of search panel
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 <qdp@odoo.com> Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
@@ -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
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user