From 3d5e66991892cec9995401e50c9018f5bbb0e127 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Thu, 6 Feb 2020 13:48:23 +0100 Subject: [PATCH] [10.0][IMP] account_financial_report_qweb: Improve performances We rely on full reconciliation and remove the HAVING clause which could be bulky as operating after the SELECT. --- .../report/open_items.py | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/account_financial_report_qweb/report/open_items.py b/account_financial_report_qweb/report/open_items.py index e8b72d4a..d939958c 100644 --- a/account_financial_report_qweb/report/open_items.py +++ b/account_financial_report_qweb/report/open_items.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # © 2016 Julien Coux (Camptocamp) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from datetime import timedelta from odoo import models, fields, api, _ @@ -414,10 +415,6 @@ FROM LEFT JOIN account_partial_reconcile pr ON ml.balance < 0 AND pr.credit_move_id = ml.id - LEFT JOIN - account_move_line ml_future - ON ml.balance < 0 AND pr.debit_move_id = ml_future.id - AND ml_future.date > %s LEFT JOIN account_move_line ml_past ON ml.balance < 0 AND pr.debit_move_id = ml_past.id @@ -428,27 +425,20 @@ FROM LEFT JOIN account_partial_reconcile pr ON ml.balance > 0 AND pr.debit_move_id = ml.id - LEFT JOIN - account_move_line ml_future - ON ml.balance > 0 AND pr.credit_move_id = ml_future.id - AND ml_future.date > %s LEFT JOIN account_move_line ml_past ON ml.balance > 0 AND pr.credit_move_id = ml_past.id AND ml_past.date <= %s """ sub_query += """ + LEFT JOIN account_full_reconcile afr ON afr.id = ml.full_reconcile_id WHERE ra.report_id = %s + AND ml.full_reconcile_id IS NULL OR afr.create_date >= %s GROUP BY ml.id, ml.balance, ml.amount_currency - HAVING - ( - ml.full_reconcile_id IS NULL - OR MAX(ml_future.id) IS NOT NULL - ) """ return sub_query @@ -617,17 +607,20 @@ ORDER BY ORDER BY a.code, ml.date, ml.id """ + full_reconcile_date = fields.Datetime.to_string( + fields.Datetime.from_string(self.date_at) + timedelta(days=1)) self.env.cr.execute( query_inject_move_line, (self.date_at, - self.date_at, self.id, - self.date_at, + full_reconcile_date, self.date_at, self.id, + full_reconcile_date, self.env.uid, self.id, - self.date_at,) + self.date_at, + ) ) def _compute_partners_and_accounts_cumul(self):