[UPDT] Foreign key constraints

This commit is contained in:
Horilla
2023-09-25 15:52:50 +05:30
parent 560575d0b1
commit 7ef0590768
17 changed files with 519 additions and 283 deletions

View File

@@ -94,6 +94,9 @@ class LeaveTypeForm(ConditionForm):
require_approval = forms.CharField(
label="Require Approval", widget=forms.RadioSelect(choices=CHOICES)
)
require_attachment = forms.CharField(
label="Require Attachment", widget=forms.RadioSelect(choices=CHOICES)
)
exclude_company_leave = forms.CharField(
label="Exclude Company Leave", widget=forms.RadioSelect(choices=CHOICES)
)
@@ -127,6 +130,9 @@ class UpdateLeaveTypeForm(ConditionForm):
require_approval = forms.CharField(
label="Require Approval", widget=forms.RadioSelect(choices=CHOICES)
)
require_attachment = forms.CharField(
label="Require Attachment", widget=forms.RadioSelect(choices=CHOICES)
)
exclude_company_leave = forms.CharField(
label="Exclude Company Leave", widget=forms.RadioSelect(choices=CHOICES)
)
@@ -179,9 +185,15 @@ class LeaveRequestCreationForm(ModelForm):
leave_type_id = cleaned_data.get("leave_type_id")
start_date_breakdown = cleaned_data.get("start_date_breakdown")
end_date_breakdown = cleaned_data.get("end_date_breakdown")
attachment = cleaned_data.get("attachment")
overlapping_requests = LeaveRequest.objects.filter(
employee_id=employee_id, start_date__lte=end_date, end_date__gte=start_date
)
if leave_type_id.require_attachment == "yes":
if attachment is None:
raise forms.ValidationError(
_("An attachment is required for this leave request")
)
if not start_date <= end_date:
raise forms.ValidationError(
_("End date should not be less than start date.")