From 28410d8e38db25a5d3337aa99811181301995531 Mon Sep 17 00:00:00 2001
From: Hoang Tran <thhoang.tr@gmail.com>
Date: Sun, 5 Sep 2021 10:49:11 +0000
Subject: [PATCH] [IMP] account: avoid fetching debit, credit in aged partner
 balance

Perform fetching, using `read` or `_read_from_database` on matched debit
and credit takes a huge amount of time, if there are too many acml being
processed. Delay fetching to `mapped` improve the performance greatly.

closes odoo/odoo#75969

Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
---
 addons/account/report/account_aged_partner_balance.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/addons/account/report/account_aged_partner_balance.py b/addons/account/report/account_aged_partner_balance.py
index edf46361bfcc..38c7218f69cb 100644
--- a/addons/account/report/account_aged_partner_balance.py
+++ b/addons/account/report/account_aged_partner_balance.py
@@ -128,9 +128,9 @@ class ReportAgedPartnerBalance(models.AbstractModel):
             # which look up the cache to determine the records to read, and has
             # quadratic complexity when the number of records is large...
             move_lines = self.env['account.move.line'].browse(aml_ids)
-            move_lines.read(['partner_id', 'company_id', 'balance', 'matched_debit_ids', 'matched_credit_ids'])
-            move_lines.mapped('matched_debit_ids').read(['max_date', 'company_id', 'amount'])
-            move_lines.mapped('matched_credit_ids').read(['max_date', 'company_id', 'amount'])
+            move_lines._read_from_database(['partner_id', 'company_id', 'balance'])
+            move_lines.mapped('matched_debit_ids')._read_from_database(['max_date', 'company_id', 'amount'])
+            move_lines.mapped('matched_credit_ids')._read_from_database(['max_date', 'company_id', 'amount'])
             for line in move_lines:
                 partner_id = line.partner_id.id or False
                 if partner_id not in partners_amount:
-- 
GitLab