diff --git a/budget/forms.py b/budget/forms.py index 5abbd845..d0a60ca7 100644 --- a/budget/forms.py +++ b/budget/forms.py @@ -120,6 +120,10 @@ class BillForm(Form): 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 negative")) + class MemberForm(Form): diff --git a/budget/messages.pot b/budget/messages.pot index b8de26f6..ef1fe234 100644 --- a/budget/messages.pot +++ b/budget/messages.pot @@ -445,3 +445,6 @@ msgstr "" msgid "each" msgstr "" + +msgid "Bills can't be negative" +msgstr "" diff --git a/budget/tests.py b/budget/tests.py index 0caf1863..452f71fd 100644 --- a/budget/tests.py +++ b/budget/tests.py @@ -283,6 +283,15 @@ class BudgetTestCase(TestCase): bill = models.Bill.query.one() self.assertEqual(bill.amount, 25) + self.app.post("/raclette/add", data={ + 'date': '2011-08-10', + 'what': u'fromage à raclette', + 'payer': members_ids[0], + 'payed_for': members_ids, + 'amount': '-25', # bill with a negative value is not possible + }) + self.assertEqual(1, models.Bill.query.count()) + # edit the bill resp = self.app.post("/raclette/edit/%s" % bill.id, data={ 'date': '2011-08-10', diff --git a/budget/translations/fr/LC_MESSAGES/messages.mo b/budget/translations/fr/LC_MESSAGES/messages.mo index c3b07a91..62efe515 100644 Binary files a/budget/translations/fr/LC_MESSAGES/messages.mo and b/budget/translations/fr/LC_MESSAGES/messages.mo differ diff --git a/budget/translations/fr/LC_MESSAGES/messages.po b/budget/translations/fr/LC_MESSAGES/messages.po index 0f021eb0..e6232c0e 100644 --- a/budget/translations/fr/LC_MESSAGES/messages.po +++ b/budget/translations/fr/LC_MESSAGES/messages.po @@ -451,3 +451,6 @@ msgstr "et les notifier vous même" msgid "each" msgstr "chacun" + +msgid "Bills can't be negative" +msgstr "Le montant d'une facture ne peut pas être négatif"