From 9d91e3b768342126368e6e1b9031524a1d500549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Mon, 11 Nov 2024 11:02:57 +0100 Subject: [PATCH] [IMP] simplify when same account used by multiple companies --- mis_builder/models/aep.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/mis_builder/models/aep.py b/mis_builder/models/aep.py index 235fdb144..63a0bc481 100644 --- a/mis_builder/models/aep.py +++ b/mis_builder/models/aep.py @@ -12,6 +12,7 @@ from odoo.tools.safe_eval import datetime, dateutil, safe_eval, time from .accounting_none import AccountingNone +from .simple_array import SimpleArray _logger = logging.getLogger(__name__) @@ -316,7 +317,7 @@ def do_queries( aml_model = aml_model.with_context(active_test=False) company_rates = self._get_company_rates(date_to) # {(domain, mode): {account_id: (debit, credit)}} - self._data = defaultdict(dict) + self._data = defaultdict(lambda: defaultdict(lambda: SimpleArray((0.0, 0.0)))) domain_by_mode = {} ends = [] for key in self._map_account_ids: @@ -366,16 +367,7 @@ def do_queries( continue # due to branches, it's possible to have multiple acc # with the same account_id - if acc["account_id"][0] in self._data[key]: - existing_debit, existing_credit = self._data[key][ - acc["account_id"][0] - ] - else: - existing_debit, existing_credit = (0.0, 0.0) - self._data[key][acc["account_id"][0]] = ( - existing_debit + debit * rate, - existing_credit + credit * rate, - ) + self._data[key][acc["account_id"][0]] += (debit * rate, credit * rate) # compute ending balances by summing initial and variation for key in ends: domain, mode = key