bill_type is now an optional parameter in the BillForm

This commit is contained in:
Tom Roussel 2024-03-03 10:18:54 +01:00
parent b602134772
commit 8acbf714f7
2 changed files with 31 additions and 2 deletions

View file

@ -364,7 +364,7 @@ class BillForm(FlaskForm):
payed_for = SelectMultipleField(
_("For whom?"), validators=[DataRequired()], coerce=int
)
bill_type = SelectField(_("Bill Type"), validators=[DataRequired()], choices=BillType.choices(), coerce=BillType)
bill_type = SelectField(_("Bill Type"), choices=BillType.choices(), coerce=BillType, default=BillType.EXPENSE)
submit = SubmitField(_("Submit"))
submit2 = SubmitField(_("Submit and add a new one"))

View file

@ -1047,4 +1047,33 @@ class TestAPI(IhatemoneyTestCase):
headers=self.get_auth("raclette")
)
self.assertStatus(201, req)
self.assertStatus(201, req)
def test_default_bill_type(self):
self.api_create("raclette")
self.api_add_member("raclette", "zorglub")
# Post a bill without adding a bill type
req = self.client.post(
"/api/projects/raclette/bills",
data={
"date": "2011-08-10",
"what": "fromage",
"payer": "1",
"payed_for": ["1"],
"amount": "50",
},
headers=self.get_auth("raclette")
)
self.assertStatus(201, req)
req = self.client.get(
"/api/projects/raclette/bills/1", headers=self.get_auth("raclette")
)
self.assertStatus(200, req)
# Bill type should now be "Expense"
got = json.loads(req.data.decode("utf-8"))
assert got["bill_type"] == "Expense"