From eddbb5a83aab63f7d127664efce14327a39ea038 Mon Sep 17 00:00:00 2001 From: Horilla Date: Tue, 28 Nov 2023 19:50:41 +0530 Subject: [PATCH] [UPDT] PMS: Objective progress and key result progress --- pms/forms.py | 10 +++- pms/models.py | 4 +- pms/templates/feedback/feedback_empty.html | 16 ------ .../okr/objective_detailed_view.html | 53 +++++++++++++++++-- 4 files changed, 59 insertions(+), 24 deletions(-) diff --git a/pms/forms.py b/pms/forms.py index e9388c50c..10aebaccf 100644 --- a/pms/forms.py +++ b/pms/forms.py @@ -338,9 +338,11 @@ class KeyResultForm(forms.ModelForm): employee_objective_id = self.initial.get("employee_objective_id") start_date = cleaned_data.get("start_date") end_date = cleaned_data.get("end_date") + target_value = cleaned_data.get("target_value") + current_value = cleaned_data.get("current_value") validate_date(start_date, end_date) - + # date comparing with objective start and end date if employee_objective_id and start_date and end_date: if start_date < employee_objective_id.start_date: raise ValidationError("Start date should be after Objective start date") @@ -349,7 +351,11 @@ class KeyResultForm(forms.ModelForm): raise ValidationError("End date should be below Objective end date") else: raise forms.ValidationError("Employee Objective not found") - + # target value and current value comparison + if target_value <= 0: + raise ValidationError("Target value should be greater than zero") + if current_value > target_value: + raise forms.ValidationError("Current value cannot be greater than target value") return cleaned_data diff --git a/pms/models.py b/pms/models.py index 5aea6180e..d279612dd 100644 --- a/pms/models.py +++ b/pms/models.py @@ -144,7 +144,9 @@ class EmployeeKeyResult(models.Model): def save(self, *args, **kwargs): if self.employee_id is None: self.employee_id = self.employee_objective_id.employee_id - self.progress_percentage = (int(self.current_value)/int(self.target_value))*100 + if self.target_value != 0: + self.progress_percentage = (int(self.current_value)/int(self.target_value))*100 + super().save(*args, **kwargs) diff --git a/pms/templates/feedback/feedback_empty.html b/pms/templates/feedback/feedback_empty.html index bcc104387..2ab9ca299 100644 --- a/pms/templates/feedback/feedback_empty.html +++ b/pms/templates/feedback/feedback_empty.html @@ -12,22 +12,6 @@ {% block content %} -{% if messages %} - -{% endif %} - -
diff --git a/pms/templates/okr/objective_detailed_view.html b/pms/templates/okr/objective_detailed_view.html index 5667f677a..37064d21c 100644 --- a/pms/templates/okr/objective_detailed_view.html +++ b/pms/templates/okr/objective_detailed_view.html @@ -62,7 +62,7 @@ {% endif %}
-
+
@@ -157,7 +157,7 @@
- {{employee_key_result.progress_percentage}}% + {{employee_key_result.progress_percentage}}%
@@ -183,13 +183,15 @@ {% trans "Current Value" %} + name="current_value" readonly + onchange="progress(this)"/> @@ -198,7 +200,8 @@ - @@ -271,4 +274,44 @@
-{% endblock %} \ No newline at end of file + + +{% endblock %} + +