From d8c36406f58fc4db378d58513ed13e5c93f8b2f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Fri, 31 Jan 2025 14:06:51 +0100 Subject: [PATCH] [IMP] mise_builder: use _read_group for better performance --- mis_builder/models/aep.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/mis_builder/models/aep.py b/mis_builder/models/aep.py index b5b604a01..52af4332b 100644 --- a/mis_builder/models/aep.py +++ b/mis_builder/models/aep.py @@ -351,11 +351,10 @@ def do_queries( try: accs = aml_model.with_context( allowed_company_ids=self.companies.ids - ).read_group( + )._read_group( domain, - ["debit", "credit", "account_id", "company_id"], - ["account_id", "company_id"], - lazy=False, + groupby=("account_id", "company_id"), + aggregates=("debit:sum", "credit:sum"), ) except ValueError as e: raise UserError( @@ -368,10 +367,10 @@ def do_queries( exception=e, ) ) from e - for acc in accs: - rate, dp = company_rates[acc["company_id"][0]] - debit = acc["debit"] or 0.0 - credit = acc["credit"] or 0.0 + for account_id, company_id, debit, credit in accs: + rate, dp = company_rates[company_id.id] + debit = debit or 0.0 + credit = credit or 0.0 if mode in (self.MODE_INITIAL, self.MODE_UNALLOCATED) and float_is_zero( debit - credit, precision_digits=self.dp ): @@ -379,7 +378,7 @@ def do_queries( continue # due to branches, it's possible to have multiple acc # with the same account_id - self._data[key][acc["account_id"][0]] += (debit * rate, credit * rate) + self._data[key][account_id.id] += (debit * rate, credit * rate) # compute ending balances by summing initial and variation for key in ends: domain, mode = key