diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index 6a787e214..dd7c85463 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"), choices=BillType.choices(), coerce=BillType, default=BillType.EXPENSE) + bill_type = SelectField(_("Bill Type"), choices=BillType.choices(), coerce=BillType.coerce, default=BillType.EXPENSE) submit = SubmitField(_("Submit")) submit2 = SubmitField(_("Submit and add a new one")) diff --git a/ihatemoney/models.py b/ihatemoney/models.py index fcc172647..ef461dae2 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -55,10 +55,17 @@ class BillType(Enum): EXPENSE = "Expense" REIMBURSEMENT = "Reimbursement" + def __str__(self): + return self.name + @classmethod def choices(cls): return [(choice, choice.value) for choice in cls] + @classmethod + def coerce(cls, item): + return item if isinstance(item, BillType) else BillType[item] + db = SQLAlchemy()