Commit e9807a73 authored by Michal Čihař's avatar Michal Čihař

Avoid conflict with self on validation

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent bf1dcce6
......@@ -170,7 +170,15 @@ class Invoice(models.Model):
overlapping = Invoice.objects.filter(
(Q(start__lte=self.end) & Q(end__gte=self.end)) |
(Q(start__lte=self.start) & Q(end__gte=self.start))
).filter(billing=self.billing)
).filter(
billing=self.billing
)
if self.pk:
overlapping = overlapping.exclude(
pk=self.pk
)
if overlapping.exists():
raise ValidationError(
'Overlapping invoices exist: {0}'.format(overlapping)
......
......@@ -122,3 +122,6 @@ class BillingTest(TestCase):
# Valid before existing
invoice.end = self.invoice.start - timedelta(days=1)
invoice.clean()
# Validation of existing
self.invoice.clean()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment