From 1439299e2ec3cb1fe1e9e4cac13b4f862552a9b6 Mon Sep 17 00:00:00 2001 From: Karl Date: Sat, 11 Feb 2023 15:06:32 +0000 Subject: [PATCH] [PERF] account.chart.template existing_accounting slow By adding an explicit order to the queries within `existing_accounting` the PostgreSQL query cost drops to `cost=0.84..1.78 rows=1 width=4` from `cost=13061.20..18895.19 rows=1 width=24` (on my local dev machine). closes odoo/odoo#112842 X-original-commit: ab34d6b0273c6766757f0596ca5f62458a9d5ab5 Signed-off-by: John Laterre (jol) --- addons/account/models/chart_template.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index eabeb477cb9..2e08bdba387 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -562,9 +562,9 @@ class AccountChartTemplate(models.Model): """ model_to_check = ['account.payment', 'account.bank.statement.line'] for model in model_to_check: - if self.env[model].sudo().search([('company_id', '=', company_id.id)], limit=1): + if self.env[model].sudo().search([('company_id', '=', company_id.id)], order="id DESC", limit=1): return True - if self.env['account.move'].sudo().search([('company_id', '=', company_id.id), ('state', '!=', 'draft')], limit=1): + if self.env['account.move'].sudo().search([('company_id', '=', company_id.id), ('state', '!=', 'draft')], order="id DESC", limit=1): return True return False