diff --git a/mis_builder/models/aep.py b/mis_builder/models/aep.py index f3588bdf1..be00bec44 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,11 @@ 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((AccountingNone, AccountingNone)), + ) + ) domain_by_mode = {} ends = [] for key in self._map_account_ids: @@ -364,7 +369,9 @@ def do_queries( ): # in initial mode, ignore accounts with 0 balance continue - self._data[key][acc["account_id"][0]] = (debit * rate, credit * rate) + # 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) # compute ending balances by summing initial and variation for key in ends: domain, mode = key diff --git a/mis_builder/tests/test_aep.py b/mis_builder/tests/test_aep.py index 74f2ffebc..ab762a515 100644 --- a/mis_builder/tests/test_aep.py +++ b/mis_builder/tests/test_aep.py @@ -83,6 +83,7 @@ def setUp(self): self.aep.parse_expr("bali[700IN]") self.aep.parse_expr("bale[700IN]") self.aep.parse_expr("balp[700IN]") + self.aep.parse_expr("balp[700NA]") # account that does not exist self.aep.parse_expr("bali[400AR]") self.aep.parse_expr("bale[400AR]") self.aep.parse_expr("balp[400AR]") @@ -193,6 +194,8 @@ def test_aep_basic(self): # check ending balance self.assertEqual(self._eval("bale[400AR]"), 400) self.assertEqual(self._eval("bale[700IN]"), -300) + # check result for non existing account + self.assertIs(self._eval("bale[700NA]"), AccountingNone) # let's query for March self._do_queries( @@ -227,9 +230,14 @@ def test_aep_basic(self): # unallocated p&l from previous year self.assertEqual(self._eval("balu[]"), -100) - # TODO allocate profits, and then... + # let's query for December where there is no data + self._do_queries( + datetime.date(self.curr_year, 12, 1), datetime.date(self.curr_year, 12, 31) + ) + self.assertIs(self._eval("balp[700IN]"), AccountingNone) + def test_aep_by_account(self): self.aep.done_parsing() self._do_queries(