diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index 9f62688d..11ce57a9 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()) + bill_type = SelectField(_("Bill Type"), validators=[DataRequired()], choices=BillType.choices(), coerce=BillType) submit = SubmitField(_("Submit")) submit2 = SubmitField(_("Submit and add a new one")) diff --git a/ihatemoney/models.py b/ihatemoney/models.py index a868772d..8638361c 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -1,4 +1,5 @@ from collections import defaultdict +from enum import Enum import datetime import itertools @@ -50,11 +51,15 @@ make_versioned( ], ) -class BillType(FormEnum): +class BillType(Enum): EXPENSE = "Expense" REIMBURSEMENT = "Reimbursement" TRANSFER = "Transfer" + @classmethod + def choices(cls): + return [(choice, choice.value) for choice in cls] + db = SQLAlchemy() diff --git a/ihatemoney/templates/list_bills.html b/ihatemoney/templates/list_bills.html index a43279d4..6f2fbbaa 100644 --- a/ihatemoney/templates/list_bills.html +++ b/ihatemoney/templates/list_bills.html @@ -133,7 +133,7 @@ {{ bill.date }} - {{ bill.bill_type }} + {{ bill.bill_type.value }} {{ bill.payer }} {{ bill.what }} {% if bill.owers|length == g.project.members|length -%}