fix dates with end_date empty

This commit is contained in:
Cayo Puigdefabregas 2023-11-16 14:17:19 +01:00
parent 88b1ea171c
commit 4120d0230b
1 changed files with 14 additions and 0 deletions

View File

@ -148,6 +148,10 @@ class MembershipForm(forms.ModelForm):
if self.instance.id:
members = members.exclude(id=self.instance.id)
if members.filter(start_date__lte=start_date, end_date=None).exists():
msg = _("This membership already exists!")
raise forms.ValidationError(msg)
if (start_date and end_date):
if start_date > end_date:
msg = _("The end date is less than the start date")
@ -161,6 +165,16 @@ class MembershipForm(forms.ModelForm):
if members.exists():
msg = _("This membership already exists!")
raise forms.ValidationError(msg)
if not end_date:
members = members.filter(
start_date__gte=start_date,
)
if members.exists():
msg = _("This membership already exists!")
raise forms.ValidationError(msg)
return end_date