diff --git a/mis_builder/tests/test_aep.py b/mis_builder/tests/test_aep.py index 4eda20cfa..8802b4c4f 100644 --- a/mis_builder/tests/test_aep.py +++ b/mis_builder/tests/test_aep.py @@ -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( @@ -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')]" @@ -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, + }, ), ], } @@ -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 @@ -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( @@ -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)