diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index 11ce57a9..ec5bd0df 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -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")) diff --git a/ihatemoney/tests/api_test.py b/ihatemoney/tests/api_test.py index f3f1d61a..ff94ebe7 100644 --- a/ihatemoney/tests/api_test.py +++ b/ihatemoney/tests/api_test.py @@ -1047,4 +1047,33 @@ class TestAPI(IhatemoneyTestCase): headers=self.get_auth("raclette") ) - self.assertStatus(201, req) \ No newline at end of file + 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" +