Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow bills with an amount of zero #1133

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions ihatemoney/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,7 @@ def set_default(self):
self.payed_for.data = self.payed_for.default

def validate_amount(self, field):
if field.data == "0":
raise ValidationError(_("Bills can't be null"))
elif decimal.Decimal(field.data) > decimal.MAX_EMAX:
if decimal.Decimal(field.data) > decimal.MAX_EMAX:
# See https://github.com/python-babel/babel/issues/821
raise ValidationError(f"Result is too high: {field.data}")

Expand Down
2 changes: 1 addition & 1 deletion ihatemoney/tests/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ def test_amount_is_null(self):
},
headers=self.get_auth("raclette"),
)
self.assertStatus(400, req)
self.assertStatus(201, req)

def test_project_creation_with_mixed_case(self):
self.api_create("Raclette")
Expand Down
11 changes: 6 additions & 5 deletions ihatemoney/tests/budget_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ def test_amount_is_null(self):
self.client.post("/raclette/members/add", data={"name": "zorglub"})

# null amount
resp = self.client.post(
self.client.post(
"/raclette/add",
data={
"date": "2016-12-31",
Expand All @@ -1600,11 +1600,12 @@ def test_amount_is_null(self):
"original_currency": "EUR",
},
)
self.assertIn('<p class="alert alert-danger">', resp.data.decode("utf-8"))

resp = self.client.get("/raclette/")
# No bills, the previous one was not added
self.assertIn("No bills", resp.data.decode("utf-8"))
# Bill should have been accepted
project = self.get_project("raclette")
self.assertEqual(project.get_bills().count(), 1)
last_bill = project.get_bills().first()
self.assertEqual(last_bill.amount, 0)

def test_decimals_on_weighted_members_list(self):
self.post_project("raclette")
Expand Down