From aa5980fda3e7b35ede97aa1df135f29a575c646f Mon Sep 17 00:00:00 2001 From: Horilla Date: Wed, 22 May 2024 10:33:48 +0530 Subject: [PATCH] [ADD] PMS: Added new field duration unit for objectives, and employeeobjective end date calculation based on the duration unit --- pms/forms.py | 3 ++- pms/models.py | 20 +++++++++++++++++++- pms/templates/okr/okr_detailed_view.html | 2 +- pms/templates/okr/okr_list.html | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/pms/forms.py b/pms/forms.py index 0f05f879e..055189eea 100644 --- a/pms/forms.py +++ b/pms/forms.py @@ -116,9 +116,10 @@ class ObjectiveForm(BaseForm): fields = [ "title", "managers", - "description", + "duration_unit", "duration", "key_result_id", + "description", "add_assignees", "assignees", "start_date", diff --git a/pms/models.py b/pms/models.py index a9835597b..edf84785d 100644 --- a/pms/models.py +++ b/pms/models.py @@ -73,6 +73,11 @@ class KeyResult(HorillaModel): class Objective(HorillaModel): """Model used for creating objectives""" + DURATION_UNIT = ( + ("days", _("Days")), + ("months", _("Months")), + ("years", _("Years")), + ) title = models.CharField( null=False, blank=False, max_length=100, verbose_name="Title" ) @@ -94,6 +99,14 @@ class Objective(HorillaModel): related_name="objective", verbose_name="Default Key results", ) + duration_unit = models.CharField( + max_length=20, + choices=DURATION_UNIT, + null=True, + blank=True, + default="days", + verbose_name="Duration Unit", + ) duration = models.IntegerField(default=1, validators=[MinValueValidator(0)]) add_assignees = models.BooleanField(default=False) archive = models.BooleanField(default=False, null=True, blank=True) @@ -199,7 +212,12 @@ class EmployeeObjective(HorillaModel): def save(self, *args, **kwargs): if not self.pk and self.objective_id and self.start_date: duration = self.objective_id.duration - self.end_date = self.start_date + relativedelta(days=duration) + if self.objective_id.duration_unit == "days": + self.end_date = self.start_date + relativedelta(days=duration) + elif self.objective_id.duration_unit == "months": + self.end_date = self.start_date + relativedelta(months=duration) + elif self.objective_id.duration_unit == "years": + self.end_date = self.start_date + relativedelta(years=duration) super().save(*args, **kwargs) def tracking(self): diff --git a/pms/templates/okr/okr_detailed_view.html b/pms/templates/okr/okr_detailed_view.html index 190017416..aeb1c1214 100644 --- a/pms/templates/okr/okr_detailed_view.html +++ b/pms/templates/okr/okr_detailed_view.html @@ -136,7 +136,7 @@
  • {% trans "Duration:" %} - {{objective.duration}} {% trans "days" %} + {{objective.duration}} {{objective.get_duration_unit_display}}
  • {% trans "Description:" %} diff --git a/pms/templates/okr/okr_list.html b/pms/templates/okr/okr_list.html index 2619b2e8b..11d1e77e0 100644 --- a/pms/templates/okr/okr_list.html +++ b/pms/templates/okr/okr_list.html @@ -237,7 +237,7 @@ {{ objective.employee_objective.all|length}} {% trans "Assignees" %}
    - {{objective.duration}} + {{objective.duration}} {{objective.get_duration_unit_display}}
    {{objective.description}}