diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py
index 2a7ba24f..4b000dc0 100644
--- a/ihatemoney/forms.py
+++ b/ihatemoney/forms.py
@@ -382,7 +382,7 @@ class BillForm(FlaskForm):
self.payed_for.data = self.payed_for.default
def validate_amount(self, field):
- if field.data == 0:
+ if field.data == "0":
raise ValidationError(_("Bills can't be null"))
diff --git a/ihatemoney/tests/api_test.py b/ihatemoney/tests/api_test.py
index f5475b11..f40d8142 100644
--- a/ihatemoney/tests/api_test.py
+++ b/ihatemoney/tests/api_test.py
@@ -910,6 +910,25 @@ class APITestCase(IhatemoneyTestCase):
self.assertEqual(resp.data.decode("utf-8").count("
-- | "), 2)
self.assertNotIn("127.0.0.1", resp.data.decode("utf-8"))
+ def test_amount_is_null(self):
+ self.api_create("raclette")
+ # add participants
+ self.api_add_member("raclette", "zorglub")
+
+ # add a bill null amount
+ req = self.client.post(
+ "/api/projects/raclette/bills",
+ data={
+ "date": "2011-08-10",
+ "what": "fromage",
+ "payer": "1",
+ "payed_for": ["1"],
+ "amount": "0",
+ },
+ headers=self.get_auth("raclette"),
+ )
+ self.assertStatus(400, req)
+
def test_project_creation_with_mixed_case(self):
self.api_create("Raclette")
# get information about it
diff --git a/ihatemoney/tests/budget_test.py b/ihatemoney/tests/budget_test.py
index f7781095..17cb63e5 100644
--- a/ihatemoney/tests/budget_test.py
+++ b/ihatemoney/tests/budget_test.py
@@ -1531,6 +1531,30 @@ class BudgetTestCase(IhatemoneyTestCase):
]
assert no_currency_bills == [(5.0, 5.0), (10.0, 10.0)]
+ def test_amount_is_null(self):
+ self.post_project("raclette")
+
+ # add participants
+ self.client.post("/raclette/members/add", data={"name": "zorglub"})
+
+ # null amount
+ resp = self.client.post(
+ "/raclette/add",
+ data={
+ "date": "2016-12-31",
+ "what": "fromage à raclette",
+ "payer": 1,
+ "payed_for": [1],
+ "amount": "0",
+ "original_currency": "EUR",
+ },
+ )
+ assert '' in resp.data.decode("utf-8")
+
+ resp = self.client.get("/raclette/")
+ # No bills, the previous one was not added
+ assert "No bills" in resp.data.decode("utf-8")
+
def test_decimals_on_weighted_members_list(self):
self.post_project("raclette")