the amount of an expense can NOT be negative

This commit is contained in:
Thomas Steen Rasmussen 2018-09-01 10:25:45 +02:00
parent 4123c2eb91
commit 1cd0551d5e

View file

@ -4,6 +4,7 @@ from django.db import models
from django.conf import settings from django.conf import settings
from django.db import models from django.db import models
from django.contrib import messages from django.contrib import messages
from django.core.exceptions import ValidationError
from utils.models import CampRelatedModel, UUIDModel from utils.models import CampRelatedModel, UUIDModel
from .email import * from .email import *
@ -27,7 +28,7 @@ class Expense(CampRelatedModel, UUIDModel):
amount = models.DecimalField( amount = models.DecimalField(
decimal_places=2, decimal_places=2,
max_digits=12, 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( 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.' 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 @property
def invoice_filename(self): def invoice_filename(self):
return os.path.basename(self.invoice.file.name) return os.path.basename(self.invoice.file.name)