Skip to content

Commit de6184b

Browse files
committed
Merge PR #668 into 17.0
Signed-off-by sbidoul
2 parents 60e77ad + ad37f07 commit de6184b

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

Diff for: mis_builder/models/aep.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ def __init__(self, custom_field_names=()):
5656
custom_field: AccountingNone for custom_field in custom_field_names
5757
}
5858

59+
def has_data(self):
60+
return (
61+
self.debit is not AccountingNone
62+
or self.credit is not AccountingNone
63+
or any(v is not AccountingNone for v in self.custom_fields.values())
64+
)
65+
5966
def add_debit_credit(self, debit, credit):
6067
self.debit += debit
6168
self.credit += credit
@@ -579,7 +586,7 @@ def f(mo):
579586
key = (ml_domain, mode)
580587
account_ids_data = self._data[key]
581588
for account_id in self._account_ids_by_acc_domain[acc_domain]:
582-
if account_id in account_ids_data:
589+
if account_ids_data[account_id].has_data():
583590
account_ids.add(account_id)
584591

585592
for account_id in account_ids:

Diff for: mis_builder/tests/test_aep.py

+25-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ def setUp(self):
5555
"account_type": "income",
5656
}
5757
)
58+
self.account_in_no_data = self.account_model.create(
59+
{
60+
"company_id": self.company.id,
61+
"code": "700INNODATA",
62+
"name": "Income (no data)",
63+
"account_type": "income",
64+
}
65+
)
5866
# create journal
5967
self.journal = self.journal_model.create(
6068
{
@@ -103,6 +111,7 @@ def setUp(self):
103111
self.aep.parse_expr("crdp[700I%]")
104112
self.aep.parse_expr("bali[400%]")
105113
self.aep.parse_expr("bale[700%]")
114+
self.aep.parse_expr("balp[700I%]")
106115
self.aep.parse_expr("fldp.quantity[700%]")
107116
self.aep.parse_expr("balp[]" "[('account_id.code', '=', '400AR')]")
108117
self.aep.parse_expr(
@@ -306,6 +315,17 @@ def test_aep_by_account(self):
306315
end = self._eval_by_account_id("bale[]")
307316
self.assertEqual(end, {self.account_ar.id: 900, self.account_in.id: -800})
308317

318+
def test_aep_by_account_no_data(self):
319+
"""Test that accounts with no data are not returned."""
320+
self.aep.done_parsing()
321+
self._do_queries(
322+
datetime.date(self.curr_year, 3, 1), datetime.date(self.curr_year, 3, 31)
323+
)
324+
variation = self._eval("balp[700I%]")
325+
self.assertEqual(variation, -500)
326+
variation_by_account = self._eval_by_account_id("balp[700I%]")
327+
self.assertEqual(variation_by_account, {self.account_in.id: -500})
328+
309329
def test_aep_convenience_methods(self):
310330
initial = AEP.get_balances_initial(self.company, time.strftime("%Y") + "-03-01")
311331
self.assertEqual(
@@ -358,10 +378,13 @@ def test_get_account_ids_for_expr(self):
358378
self.assertEqual(account_ids, {self.account_in.id})
359379
expr = "balp[700%]"
360380
account_ids = self.aep.get_account_ids_for_expr(expr)
361-
self.assertEqual(account_ids, {self.account_in.id})
381+
self.assertEqual(account_ids, {self.account_in.id, self.account_in_no_data.id})
362382
expr = "bali[400%], bale[700%]" # subkpis combined expression
363383
account_ids = self.aep.get_account_ids_for_expr(expr)
364-
self.assertEqual(account_ids, {self.account_in.id, self.account_ar.id})
384+
self.assertEqual(
385+
account_ids,
386+
{self.account_in.id, self.account_ar.id, self.account_in_no_data.id},
387+
)
365388

366389
def test_get_aml_domain_for_expr(self):
367390
self.aep.done_parsing()

0 commit comments

Comments
 (0)