Skip to content

Commit 3452163

Browse files
committed
Merge PR #667 into 16.0
Signed-off-by sbidoul
2 parents b511cec + 2db096e commit 3452163

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
@@ -48,6 +48,14 @@ def setUp(self):
4848
"account_type": "income",
4949
}
5050
)
51+
self.account_in_no_data = self.account_model.create(
52+
{
53+
"company_id": self.company.id,
54+
"code": "700INNODATA",
55+
"name": "Income (no data)",
56+
"account_type": "income",
57+
}
58+
)
5159
# create journal
5260
self.journal = self.journal_model.create(
5361
{
@@ -96,6 +104,7 @@ def setUp(self):
96104
self.aep.parse_expr("crdp[700I%]")
97105
self.aep.parse_expr("bali[400%]")
98106
self.aep.parse_expr("bale[700%]")
107+
self.aep.parse_expr("balp[700I%]")
99108
self.aep.parse_expr("fldp.quantity[700%]")
100109
self.aep.parse_expr("balp[]" "[('account_id.code', '=', '400AR')]")
101110
self.aep.parse_expr(
@@ -299,6 +308,17 @@ def test_aep_by_account(self):
299308
end = self._eval_by_account_id("bale[]")
300309
self.assertEqual(end, {self.account_ar.id: 900, self.account_in.id: -800})
301310

311+
def test_aep_by_account_no_data(self):
312+
"""Test that accounts with no data are not returned."""
313+
self.aep.done_parsing()
314+
self._do_queries(
315+
datetime.date(self.curr_year, 3, 1), datetime.date(self.curr_year, 3, 31)
316+
)
317+
variation = self._eval("balp[700I%]")
318+
self.assertEqual(variation, -500)
319+
variation_by_account = self._eval_by_account_id("balp[700I%]")
320+
self.assertEqual(variation_by_account, {self.account_in.id: -500})
321+
302322
def test_aep_convenience_methods(self):
303323
initial = AEP.get_balances_initial(self.company, time.strftime("%Y") + "-03-01")
304324
self.assertEqual(
@@ -351,10 +371,13 @@ def test_get_account_ids_for_expr(self):
351371
self.assertEqual(account_ids, {self.account_in.id})
352372
expr = "balp[700%]"
353373
account_ids = self.aep.get_account_ids_for_expr(expr)
354-
self.assertEqual(account_ids, {self.account_in.id})
374+
self.assertEqual(account_ids, {self.account_in.id, self.account_in_no_data.id})
355375
expr = "bali[400%], bale[700%]" # subkpis combined expression
356376
account_ids = self.aep.get_account_ids_for_expr(expr)
357-
self.assertEqual(account_ids, {self.account_in.id, self.account_ar.id})
377+
self.assertEqual(
378+
account_ids,
379+
{self.account_in.id, self.account_ar.id, self.account_in_no_data.id},
380+
)
358381

359382
def test_get_aml_domain_for_expr(self):
360383
self.aep.done_parsing()

0 commit comments

Comments
 (0)