Skip to content

Commit

Permalink
Merge PR #668 into 17.0
Browse files Browse the repository at this point in the history
Signed-off-by sbidoul
  • Loading branch information
OCA-git-bot committed Jan 8, 2025
2 parents 60e77ad + ad37f07 commit de6184b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
9 changes: 8 additions & 1 deletion mis_builder/models/aep.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ def __init__(self, custom_field_names=()):
custom_field: AccountingNone for custom_field in custom_field_names
}

def has_data(self):
return (
self.debit is not AccountingNone
or self.credit is not AccountingNone
or any(v is not AccountingNone for v in self.custom_fields.values())
)

def add_debit_credit(self, debit, credit):
self.debit += debit
self.credit += credit
Expand Down Expand Up @@ -579,7 +586,7 @@ def f(mo):
key = (ml_domain, mode)
account_ids_data = self._data[key]
for account_id in self._account_ids_by_acc_domain[acc_domain]:
if account_id in account_ids_data:
if account_ids_data[account_id].has_data():
account_ids.add(account_id)

for account_id in account_ids:
Expand Down
27 changes: 25 additions & 2 deletions mis_builder/tests/test_aep.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ def setUp(self):
"account_type": "income",
}
)
self.account_in_no_data = self.account_model.create(
{
"company_id": self.company.id,
"code": "700INNODATA",
"name": "Income (no data)",
"account_type": "income",
}
)
# create journal
self.journal = self.journal_model.create(
{
Expand Down Expand Up @@ -103,6 +111,7 @@ def setUp(self):
self.aep.parse_expr("crdp[700I%]")
self.aep.parse_expr("bali[400%]")
self.aep.parse_expr("bale[700%]")
self.aep.parse_expr("balp[700I%]")
self.aep.parse_expr("fldp.quantity[700%]")
self.aep.parse_expr("balp[]" "[('account_id.code', '=', '400AR')]")
self.aep.parse_expr(
Expand Down Expand Up @@ -306,6 +315,17 @@ def test_aep_by_account(self):
end = self._eval_by_account_id("bale[]")
self.assertEqual(end, {self.account_ar.id: 900, self.account_in.id: -800})

def test_aep_by_account_no_data(self):
"""Test that accounts with no data are not returned."""
self.aep.done_parsing()
self._do_queries(
datetime.date(self.curr_year, 3, 1), datetime.date(self.curr_year, 3, 31)
)
variation = self._eval("balp[700I%]")
self.assertEqual(variation, -500)
variation_by_account = self._eval_by_account_id("balp[700I%]")
self.assertEqual(variation_by_account, {self.account_in.id: -500})

def test_aep_convenience_methods(self):
initial = AEP.get_balances_initial(self.company, time.strftime("%Y") + "-03-01")
self.assertEqual(
Expand Down Expand Up @@ -358,10 +378,13 @@ def test_get_account_ids_for_expr(self):
self.assertEqual(account_ids, {self.account_in.id})
expr = "balp[700%]"
account_ids = self.aep.get_account_ids_for_expr(expr)
self.assertEqual(account_ids, {self.account_in.id})
self.assertEqual(account_ids, {self.account_in.id, self.account_in_no_data.id})
expr = "bali[400%], bale[700%]" # subkpis combined expression
account_ids = self.aep.get_account_ids_for_expr(expr)
self.assertEqual(account_ids, {self.account_in.id, self.account_ar.id})
self.assertEqual(
account_ids,
{self.account_in.id, self.account_ar.id, self.account_in_no_data.id},
)

def test_get_aml_domain_for_expr(self):
self.aep.done_parsing()
Expand Down

0 comments on commit de6184b

Please sign in to comment.