Skip to content

Commit

Permalink
[TST] add test for fldp
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Nov 11, 2024
1 parent 8964695 commit 1e2aed9
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions mis_builder/tests/test_aep.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def setUp(self):
amount=300,
debit_acc=self.account_ar,
credit_acc=self.account_in,
credit_quantity=3,
)
# create move in March this year
self._create_move(
Expand All @@ -95,6 +96,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("fldp.quantity[700%]")
self.aep.parse_expr("balp[]" "[('account_id.code', '=', '400AR')]")
self.aep.parse_expr(
"balp[]" "[('account_id.account_type', '=', " " 'asset_receivable')]"
Expand All @@ -109,17 +111,32 @@ def setUp(self):
self.aep.parse_expr("bal_700IN") # deprecated
self.aep.parse_expr("bals[700IN]") # deprecated

def _create_move(self, date, amount, debit_acc, credit_acc, post=True):
def _create_move(
self, date, amount, debit_acc, credit_acc, post=True, credit_quantity=0
):
move = self.move_model.create(
{
"journal_id": self.journal.id,
"date": fields.Date.to_string(date),
"line_ids": [
(0, 0, {"name": "/", "debit": amount, "account_id": debit_acc.id}),
(
0,
0,
{"name": "/", "credit": amount, "account_id": credit_acc.id},
{
"name": "/",
"debit": amount,
"account_id": debit_acc.id,
},
),
(
0,
0,
{
"name": "/",
"credit": amount,
"account_id": credit_acc.id,
"quantity": credit_quantity,
},
),
],
}
Expand Down Expand Up @@ -149,6 +166,20 @@ def test_sanity_check(self):
self.assertEqual(self.company.fiscalyear_last_day, 31)
self.assertEqual(self.company.fiscalyear_last_month, "12")

def test_parse_expr_error_handling(self):
aep = AEP(self.company)
with self.assertRaises(UserError) as cm:
aep.parse_expr("fldi.quantity[700%]")
self.assertIn(
"`fld` can only be used with mode `p` (variation)", str(cm.exception)
)
with self.assertRaises(UserError) as cm:
aep.parse_expr("fldp[700%]")
self.assertIn("`fld` must have a field name", str(cm.exception))
with self.assertRaises(UserError) as cm:
aep.parse_expr("balp.quantity[700%]")
self.assertIn("`bal` cannot have a field name", str(cm.exception))

def test_aep_basic(self):
self.aep.done_parsing()
# let's query for december
Expand Down Expand Up @@ -200,6 +231,8 @@ def test_aep_basic(self):
self.assertEqual(self._eval("bale[700IN]"), -300)
# check result for non existing account
self.assertIs(self._eval("bale[700NA]"), AccountingNone)
# check fldp.quantity
self.assertEqual(self._eval("fldp.quantity[700%]"), 3)

# let's query for March
self._do_queries(
Expand Down Expand Up @@ -231,6 +264,8 @@ def test_aep_basic(self):
self.assertEqual(self._eval("debp[400A%]"), 500)
self.assertEqual(self._eval("bal_700IN"), -500)
self.assertEqual(self._eval("bals[700IN]"), -800)
# check fldp.quantity
self.assertEqual(self._eval("fldp.quantity[700%]"), 0)

# unallocated p&l from previous year
self.assertEqual(self._eval("balu[]"), -100)
Expand Down

0 comments on commit 1e2aed9

Please sign in to comment.