[FIX] LEAVE: Prevent duplicate compensatory leave types by excluding current instance in model validation
This commit is contained in:
@@ -281,8 +281,14 @@ class LeaveType(HorillaModel):
|
||||
|
||||
def clean(self, *args, **kwargs):
|
||||
if self.is_compensatory_leave:
|
||||
if LeaveType.objects.filter(is_compensatory_leave=True).count() >= 1:
|
||||
raise ValidationError(_("Compensatory Leave Request already exists."))
|
||||
if (
|
||||
LeaveType.objects.filter(is_compensatory_leave=True)
|
||||
.exclude(pk=self.pk)
|
||||
.exists()
|
||||
):
|
||||
raise ValidationError(
|
||||
{"name": _("Compensatory Leave Request already exists.")}
|
||||
)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user