Skip to content
Snippets Groups Projects
Verified Commit 3a33fc04 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Fix constraints for manual invoicing

parent 6612dd6e
No related branches found
No related tags found
No related merge requests found
Pipeline #59657 failed
...@@ -67,8 +67,10 @@ class Invoice(BasePayment, PureDjangoModel): ...@@ -67,8 +67,10 @@ class Invoice(BasePayment, PureDjangoModel):
number = models.CharField(verbose_name=_("Invoice number"), max_length=255) number = models.CharField(verbose_name=_("Invoice number"), max_length=255)
due_date = models.DateField(verbose_name=_("Payment due date"), null=True) due_date = models.DateField(verbose_name=_("Payment due date"), null=True)
for_content_type = models.ForeignKey(ContentType, on_delete=models.SET_NULL, null=True) for_content_type = models.ForeignKey(
for_object_id = models.PositiveIntegerField() ContentType, on_delete=models.SET_NULL, null=True, blank=True
)
for_object_id = models.PositiveIntegerField(null=True, blank=True)
for_object = GenericForeignKey("for_content_type", "for_object_id") for_object = GenericForeignKey("for_content_type", "for_object_id")
# For manual invoicing # For manual invoicing
...@@ -119,7 +121,10 @@ class Invoice(BasePayment, PureDjangoModel): ...@@ -119,7 +121,10 @@ class Invoice(BasePayment, PureDjangoModel):
constraints = [ constraints = [
models.UniqueConstraint(fields=["number", "group"], name="number_uniq_per_group"), models.UniqueConstraint(fields=["number", "group"], name="number_uniq_per_group"),
models.CheckConstraint( models.CheckConstraint(
check=(Q(for_object_id__isnull=True) | Q(person__isnull=True)), check=(
(Q(for_object_id__isnull=True) & Q(person__isnull=False))
| (Q(for_object_id__isnull=False) & Q(person__isnull=True))
),
name="object_or_person", name="object_or_person",
), ),
] ]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment