diff --git a/pms/filters.py b/pms/filters.py index 3288b7384..5ccf6a95a 100644 --- a/pms/filters.py +++ b/pms/filters.py @@ -265,3 +265,52 @@ class ObjectiveReGroup: ("employee_id", "Owner"), ("status", "Status"), ] + +class EmployeeObjectiveFilter(FilterSet): + """ + Filter through EmployeeObjective model + """ + + search = django_filters.CharFilter(method="search_method") + start_date_from = django_filters.DateFilter( + field_name="start_date", + lookup_expr="gte", + widget=forms.DateInput(attrs={"type": "date"}), + ) + start_date_till = django_filters.DateFilter( + field_name="start_date", + lookup_expr="lte", + widget=forms.DateInput(attrs={"type": "date"}), + ) + end_date_from = django_filters.DateFilter( + field_name="end_date", + lookup_expr="gte", + widget=forms.DateInput(attrs={"type": "date"}), + ) + end_date_till = django_filters.DateFilter( + field_name="end_date", + lookup_expr="lte", + widget=forms.DateInput(attrs={"type": "date"}), + ) + class Meta: + model = EmployeeObjective + fields = [ + "status", + "archive", + "key_result_id", + 'start_date', + 'end_date', + 'employee_id', + ] + + def search_method(self, queryset, _, value: str): + """ + This method is used to search employees and objective + """ + values = value.split(" ") + empty = queryset.model.objects.none() + for split in values: + empty = empty | (queryset.filter(employee_id__employee_first_name__icontains=split))|(queryset.filter(employee_id__employee_last_name__icontains=split)) + + + return empty.distinct() \ No newline at end of file diff --git a/pms/forms.py b/pms/forms.py index 250b5079f..87633ca47 100644 --- a/pms/forms.py +++ b/pms/forms.py @@ -115,27 +115,25 @@ class ObjectiveForm(BaseForm): "managers", "description", "duration", - 'key_result_id', + "key_result_id", "add_assignees", "assignees", - # 'period', "start_date", - # 'end_date', - # 'archive', ] + exclude = ["is_active"] widgets = { - "key_result_id":forms.SelectMultiple( + "key_result_id": forms.SelectMultiple( attrs={ "class": "oh-select oh-select-2 select2-hidden-accessible", "onchange": "keyResultChange($(this))", } ), - # "start_date": forms.DateInput( - # attrs={"class": "oh-input w-100", "type": "date"} - # ), - # "end_date": forms.DateInput( - # attrs={"class": "oh-input w-100", "type": "date"} - # ), + # "start_date": forms.DateInput( + # attrs={"class": "oh-input w-100", "type": "date"} + # ), + # "end_date": forms.DateInput( + # attrs={"class": "oh-input w-100", "type": "date"} + # ), } def __init__(self, *args, **kwargs): @@ -285,6 +283,7 @@ class EmployeeObjectiveForm(BaseForm): "status", "archive", ] + exclude = ["is_active"] widgets = { "objective_id": forms.HiddenInput(), "start_date": forms.DateInput( @@ -302,7 +301,6 @@ class EmployeeObjectiveForm(BaseForm): del self.fields["key_result_id"] except Exception as _err: pass - def as_p(self): """ @@ -402,6 +400,7 @@ class KRForm(MF): exclude = [ "history", "objects", + "is_active", ] def as_p(self): @@ -411,33 +410,32 @@ class KRForm(MF): context = {"form": self} table_html = render_to_string("common_form.html", context) return table_html - + def clean(self): cleaned_data = super().clean() - duration = cleaned_data.get('duration') - target_value = cleaned_data.get('target_value') - progress_type = cleaned_data.get('progress_type') + duration = cleaned_data.get("duration") + target_value = cleaned_data.get("target_value") + progress_type = cleaned_data.get("progress_type") - if duration is None or duration == '': - raise ValidationError({ - 'duration':'This field is required' - }) - if target_value is None or target_value == '': - raise ValidationError({ - 'target_value':'This field is required' - }) + if duration is None or duration == "": + raise ValidationError({"duration": "This field is required"}) + if target_value is None or target_value == "": + raise ValidationError({"target_value": "This field is required"}) if duration <= 0: - raise ValidationError({ - 'duration':'Duration cannot be less than or equal to zero' - }) + raise ValidationError( + {"duration": "Duration cannot be less than or equal to zero"} + ) if target_value <= 0: - raise ValidationError({ - 'target_value':'Duration cannot be less than or equal to zero' - }) - if progress_type == '%' and target_value > 100 : - raise ValidationError({ - 'target_value':'Target value cannot be greater than hundred for progress type "percentage"' - }) + raise ValidationError( + {"target_value": "Duration cannot be less than or equal to zero"} + ) + if progress_type == "%" and target_value > 100: + raise ValidationError( + { + "target_value": 'Target value cannot be greater than hundred for progress type "percentage"' + } + ) + class KeyResultForm(ModelForm): """ @@ -615,7 +613,7 @@ class FeedbackForm(ModelForm): model = Feedback fields = "__all__" - exclude = ["status", "archive"] + exclude = ["status", "archive", "is_active"] widgets = { "review_cycle": forms.TextInput( @@ -753,6 +751,7 @@ class QuestionTemplateForm(ModelForm): model = QuestionTemplate fields = "__all__" + exclude = ["is_active"] def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) @@ -816,7 +815,7 @@ class QuestionForm(ModelForm): """ model = Question - exclude = ["question_option_id", "template_id"] + exclude = ["question_option_id", "template_id", "is_active"] widgets = { "question_type": forms.Select( attrs={ @@ -890,6 +889,7 @@ class PeriodForm(ModelForm): model = Period fields = "__all__" + exclude = ["is_active"] widgets = { "period_name": forms.TextInput( attrs={"placeholder": "Q1.", "class": "oh-input w-100"} diff --git a/pms/models.py b/pms/models.py index d0dc0d365..c041944db 100644 --- a/pms/models.py +++ b/pms/models.py @@ -2,21 +2,19 @@ from django import forms from django.db import models from django.core.exceptions import ValidationError from django.utils.translation import gettext_lazy as _ -from base.models import Company, Department, JobPosition -from base.horilla_company_manager import HorillaCompanyManager -from horilla_audit.methods import get_diff - -# importing simple history -from simple_history.models import HistoricalRecords -from employee.models import Employee -from horilla_audit.models import HorillaAuditLog, HorillaAuditInfo from django.core.validators import MinValueValidator from dateutil.relativedelta import relativedelta +from horilla.models import HorillaModel +from horilla_audit.methods import get_diff +from horilla_audit.models import HorillaAuditLog, HorillaAuditInfo +from base.models import Company, Department, JobPosition +from base.horilla_company_manager import HorillaCompanyManager +from employee.models import Employee """Objectives and key result section""" -class Period(models.Model): +class Period(HorillaModel): """this is a period model used for creating period""" period_name = models.CharField(max_length=150, unique=True) @@ -29,7 +27,7 @@ class Period(models.Model): return self.period_name -class KeyResult(models.Model): +class KeyResult(HorillaModel): """model used to create key results""" PROGRESS_CHOICES = ( @@ -71,7 +69,7 @@ class KeyResult(models.Model): return f"{self.title}" -class Objective(models.Model): +class Objective(HorillaModel): """Model used for creating objectives""" title = models.CharField( @@ -96,7 +94,6 @@ class Objective(models.Model): verbose_name="Default Key results", ) duration = models.IntegerField(default=1, validators=[MinValueValidator(0)]) - created_at = models.DateField(auto_now_add=True) add_assignees = models.BooleanField(default=False) archive = models.BooleanField(default=False, null=True, blank=True) history = HorillaAuditLog(bases=[HorillaAuditInfo]) @@ -122,7 +119,7 @@ class Objective(models.Model): return f"{self.title}" -class EmployeeObjective(models.Model): +class EmployeeObjective(HorillaModel): """this is a EmployObjective model used for creating Employee objectives""" STATUS_CHOICES = ( @@ -236,7 +233,7 @@ class Comment(models.Model): return f"{self.employee_id.employee_first_name} - {self.comment} " -class EmployeeKeyResult(models.Model): +class EmployeeKeyResult(models.Model): """employee key result creation""" PROGRESS_CHOICES = ( @@ -349,10 +346,10 @@ class EmployeeKeyResult(models.Model): # unique_together = ("key_result_id", "employee_objective_id") -"""360degree feedback section""" +"""360degree feedback section""" -class QuestionTemplate(models.Model): +class QuestionTemplate(HorillaModel): """question template creation""" question_template = models.CharField( @@ -366,7 +363,7 @@ class QuestionTemplate(models.Model): return self.question_template -class Question(models.Model): +class Question(HorillaModel): """question creation""" QUESTION_TYPE_CHOICE = ( @@ -393,7 +390,7 @@ class Question(models.Model): return self.question -class QuestionOptions(models.Model): +class QuestionOptions(HorillaModel): """options for question""" question_id = models.ForeignKey( @@ -410,7 +407,7 @@ class QuestionOptions(models.Model): objects = HorillaCompanyManager("question_id__template_id__company_id") -class Feedback(models.Model): +class Feedback(HorillaModel): """feedback model for creating feedback""" STATUS_CHOICES = ( @@ -456,7 +453,6 @@ class Feedback(models.Model): status = models.CharField( max_length=50, choices=STATUS_CHOICES, default="Not Started" ) - created_at = models.DateField(auto_now_add=True) archive = models.BooleanField(null=True, blank=True, default=False) start_date = models.DateField(null=False, blank=False) end_date = models.DateField(null=True, blank=False) @@ -549,6 +545,7 @@ class AnonymousFeedback(models.Model): max_length=10, null=True, blank=False, editable=False ) feedback_description = models.TextField(null=True, blank=True, max_length=255) + objects = models.Manager() def __str__(self) -> str: return f"Feedback based on a {self.based_on}" diff --git a/pms/templates/okr/emp_objective/emp_objective_list.html b/pms/templates/okr/emp_objective/emp_objective_list.html index 4e50c04bf..b0f9f9a37 100644 --- a/pms/templates/okr/emp_objective/emp_objective_list.html +++ b/pms/templates/okr/emp_objective/emp_objective_list.html @@ -1,12 +1,16 @@ {% load static i18n %} {% load i18n %} {% load widget_tweaks %} {% load basefilters %} {% load pmsfilters %} - -{% for emp_objective in objective.employee_objective.all %} +{% include "filter_tags.html" %} +{% for emp_objective in emp_objectives %} {% if perms.pms.view_employeeobjective or emp_objective|is_manager_or_owner:request.user %}