Skip to content

Commit

Permalink
Allow bills with an amount of zero
Browse files Browse the repository at this point in the history
Bills with an amount of zero may be useful to remember that a transaction
happened on a specific date, while the amount doesn't matter.

I use that with per-year projects when a reimbursement happens in year N
but is relative to year N-1: I record it with an amount of zero in the
project of year N, and with the real amount in the project of year N-1.

Besides, it's already possible to create such bills: while "0" is refused,
"0.0" is accepted.  There are no visible issues with this kind of bills.
  • Loading branch information
Baptiste Jonglez authored and zorun committed Feb 3, 2023
1 parent 35013ef commit 081f8dc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
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

0 comments on commit 081f8dc

Please sign in to comment.