From 1cd0551d5e1192c05750fe1ce49a3e3436eec7f3 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Sat, 1 Sep 2018 10:25:45 +0200 Subject: [PATCH] the amount of an expense can NOT be negative --- src/economy/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/economy/models.py b/src/economy/models.py index aa8729c7..d94d816e 100644 --- a/src/economy/models.py +++ b/src/economy/models.py @@ -4,6 +4,7 @@ from django.db import models from django.conf import settings from django.db import models from django.contrib import messages +from django.core.exceptions import ValidationError from utils.models import CampRelatedModel, UUIDModel from .email import * @@ -27,7 +28,7 @@ class Expense(CampRelatedModel, UUIDModel): amount = models.DecimalField( decimal_places=2, max_digits=12, - help_text='The amount of this expense in DKK. Must match the amount on the invoice uploaded below. The amount can be negative in some cases (like when returning bottle deposit).', + help_text='The amount of this expense in DKK. Must match the amount on the invoice uploaded below.', ) description = models.CharField( @@ -71,6 +72,10 @@ class Expense(CampRelatedModel, UUIDModel): help_text='Economy Team notes for this expense. Only visible to the Economy team and the submitting user.' ) + def clean(self): + if self.amount < 0: + raise ValidationError('Amount of an expense can not be negative') + @property def invoice_filename(self): return os.path.basename(self.invoice.file.name)