diff --git a/employee/forms.py b/employee/forms.py index 6f542d954..148c3e710 100644 --- a/employee/forms.py +++ b/employee/forms.py @@ -593,6 +593,18 @@ class BonusPointRedeemForm(ModelForm): model = BonusPoint fields = ["points"] + def clean(self): + cleaned_data = super().clean() + available_points = BonusPoint.objects.filter( + employee_id=self.instance.employee_id + ).first() + if available_points.points < cleaned_data["points"]: + raise forms.ValidationError({"points": "Not enough bonus points to redeem"}) + if cleaned_data["points"] <= 0: + raise forms.ValidationError( + {"points": "Points must be greater than zero to redeem."} + ) + class DisciplinaryActionForm(ModelForm): class Meta: diff --git a/employee/templates/tabs/forms/redeem_points_form.html b/employee/templates/tabs/forms/redeem_points_form.html index 2bf849aa7..3e11f0552 100644 --- a/employee/templates/tabs/forms/redeem_points_form.html +++ b/employee/templates/tabs/forms/redeem_points_form.html @@ -10,24 +10,25 @@ >