Skip to content

Commit

Permalink
[IMP] mise_builder: use _read_group for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Jan 31, 2025
1 parent bc34ec2 commit d8c3640
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions mis_builder/models/aep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -368,18 +367,18 @@ 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
):
# in initial mode, ignore accounts with 0 balance
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
Expand Down

0 comments on commit d8c3640

Please sign in to comment.