[IMP] Multi Company in Horilla
This commit is contained in:
@@ -9,6 +9,7 @@ import django_filters
|
||||
from django import forms
|
||||
from django_filters import DateFilter
|
||||
from pms.models import EmployeeKeyResult, EmployeeObjective, Feedback
|
||||
from base.methods import reload_queryset
|
||||
|
||||
|
||||
class DateRangeFilter(django_filters.Filter):
|
||||
@@ -44,21 +45,22 @@ class DateRangeFilter(django_filters.Filter):
|
||||
class CustomFilterSet(django_filters.FilterSet):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
for field_name, field in self.filters.items():
|
||||
reload_queryset(self.form.fields)
|
||||
for field_name, field in self.form.fields.items():
|
||||
filter_widget = self.filters[field_name]
|
||||
widget = filter_widget.field.widget
|
||||
if isinstance(
|
||||
widget, (forms.NumberInput, forms.EmailInput, forms.TextInput)
|
||||
):
|
||||
filter_widget.field.widget.attrs.update({"class": "oh-input w-100"})
|
||||
field.widget.attrs.update({"class": "oh-input w-100"})
|
||||
elif isinstance(widget, (forms.Select,)):
|
||||
filter_widget.field.widget.attrs.update(
|
||||
field.widget.attrs.update(
|
||||
{
|
||||
"class": "oh-select oh-select-2 select2-hidden-accessible",
|
||||
}
|
||||
)
|
||||
elif isinstance(widget, (forms.Textarea)):
|
||||
filter_widget.field.widget.attrs.update({"class": "oh-input w-100"})
|
||||
field.widget.attrs.update({"class": "oh-input w-100"})
|
||||
elif isinstance(
|
||||
widget,
|
||||
(
|
||||
@@ -66,11 +68,11 @@ class CustomFilterSet(django_filters.FilterSet):
|
||||
forms.CheckboxSelectMultiple,
|
||||
),
|
||||
):
|
||||
filter_widget.field.widget.attrs.update(
|
||||
field.widget.attrs.update(
|
||||
{"class": "oh-switch__checkbox"}
|
||||
)
|
||||
elif isinstance(widget, (forms.ModelChoiceField)):
|
||||
filter_widget.field.widget.attrs.update(
|
||||
field.widget.attrs.update(
|
||||
{
|
||||
"class": "oh-select oh-select-2 select2-hidden-accessible",
|
||||
}
|
||||
|
||||
51
pms/forms.py
51
pms/forms.py
@@ -3,11 +3,16 @@ forms.py
|
||||
|
||||
This module is used to register the forms for pms models
|
||||
"""
|
||||
from typing import Any
|
||||
import uuid
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.files.base import File
|
||||
from django.db.models.base import Model
|
||||
from django.forms.utils import ErrorList
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from employee.models import Department, JobPosition
|
||||
from base.forms import ModelForm
|
||||
from pms.models import (
|
||||
Question,
|
||||
EmployeeObjective,
|
||||
@@ -19,6 +24,7 @@ from pms.models import (
|
||||
Employee,
|
||||
QuestionTemplate,
|
||||
)
|
||||
from base.methods import reload_queryset
|
||||
|
||||
|
||||
def validate_date(start_date, end_date):
|
||||
@@ -39,7 +45,7 @@ def set_date_field_initial(instance):
|
||||
return initial
|
||||
|
||||
|
||||
class ObjectiveForm(forms.ModelForm):
|
||||
class ObjectiveForm(ModelForm):
|
||||
"""
|
||||
A form to create or update instances of the EmployeeObjective model.
|
||||
"""
|
||||
@@ -143,13 +149,11 @@ class ObjectiveForm(forms.ModelForm):
|
||||
employee = kwargs.pop(
|
||||
"employee", None
|
||||
) # access the logged-in user's information
|
||||
super(ObjectiveForm, self).__init__(*args, **kwargs)
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
reload_queryset(self.fields)
|
||||
self.fields["period"].choices = list(self.fields["period"].choices)
|
||||
self.fields["period"].choices.append(
|
||||
("create_new_period", "Create new period")
|
||||
)
|
||||
|
||||
self.fields["period"].choices.append(("create_new_period", "Create new period"))
|
||||
|
||||
if employee and Employee.objects.filter(
|
||||
employee_work_info__reporting_manager_id=employee
|
||||
):
|
||||
@@ -210,7 +214,7 @@ class ObjectiveForm(forms.ModelForm):
|
||||
return cleaned_data
|
||||
|
||||
|
||||
class KeyResultForm(forms.ModelForm):
|
||||
class KeyResultForm(ModelForm):
|
||||
"""
|
||||
A form used for creating and updating EmployeeKeyResult objects.
|
||||
|
||||
@@ -295,6 +299,7 @@ class KeyResultForm(forms.ModelForm):
|
||||
"employee", None
|
||||
) # access the logged-in user's information
|
||||
super().__init__(*args, **kwargs)
|
||||
reload_queryset(self.fields)
|
||||
employees = Employee.objects.filter(
|
||||
employee_work_info__reporting_manager_id=employee
|
||||
)
|
||||
@@ -359,7 +364,7 @@ class KeyResultForm(forms.ModelForm):
|
||||
return cleaned_data
|
||||
|
||||
|
||||
class FeedbackForm(forms.ModelForm):
|
||||
class FeedbackForm(ModelForm):
|
||||
"""
|
||||
A form used for creating and updating Feedback objects.
|
||||
"""
|
||||
@@ -445,12 +450,10 @@ class FeedbackForm(forms.ModelForm):
|
||||
if instance:
|
||||
kwargs["initial"] = set_date_field_initial(instance)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
reload_queryset(self.fields)
|
||||
self.fields["period"].choices = list(self.fields["period"].choices)
|
||||
self.fields["period"].choices.append(
|
||||
("create_new_period", "Create new period")
|
||||
)
|
||||
|
||||
self.fields["period"].choices.append(("create_new_period", "Create new period"))
|
||||
|
||||
if instance:
|
||||
self.fields["employee_id"].widget.attrs.update(
|
||||
{"class": "oh-select oh-select-2"}
|
||||
@@ -486,7 +489,7 @@ class FeedbackForm(forms.ModelForm):
|
||||
return cleaned_data
|
||||
|
||||
|
||||
class QuestionTemplateForm(forms.ModelForm):
|
||||
class QuestionTemplateForm(ModelForm):
|
||||
"""
|
||||
Form for creating or updating a question template instance
|
||||
"""
|
||||
@@ -508,8 +511,12 @@ class QuestionTemplateForm(forms.ModelForm):
|
||||
model = QuestionTemplate
|
||||
fields = "__all__"
|
||||
|
||||
def __init__(self, *args, **kwargs) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
reload_queryset(self.fields)
|
||||
|
||||
class QuestionForm(forms.ModelForm):
|
||||
|
||||
class QuestionForm(ModelForm):
|
||||
"""
|
||||
Form for creating or updating a question instance
|
||||
"""
|
||||
@@ -574,6 +581,7 @@ class QuestionForm(forms.ModelForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
reload_queryset(self.fields)
|
||||
self.fields["question_type"].widget.attrs.update({"id": str(uuid.uuid4())})
|
||||
if (
|
||||
self.instance.pk
|
||||
@@ -594,7 +602,7 @@ class QuestionForm(forms.ModelForm):
|
||||
].initial = self.instance.question_options.first().option_d
|
||||
|
||||
|
||||
class ObjectiveCommentForm(forms.ModelForm):
|
||||
class ObjectiveCommentForm(ModelForm):
|
||||
"""
|
||||
A form used to add a comment to an employee's objective.
|
||||
Excludes fields for the employee and employee objective and uses a textarea widget for the comment field.
|
||||
@@ -617,8 +625,12 @@ class ObjectiveCommentForm(forms.ModelForm):
|
||||
),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
reload_queryset(self.fields)
|
||||
|
||||
class PeriodForm(forms.ModelForm):
|
||||
|
||||
class PeriodForm(ModelForm):
|
||||
"""
|
||||
A form for creating or updating a Period object.
|
||||
"""
|
||||
@@ -649,7 +661,8 @@ class PeriodForm(forms.ModelForm):
|
||||
"""
|
||||
if instance := kwargs.get("instance"):
|
||||
kwargs["initial"] = set_date_field_initial(instance)
|
||||
super(PeriodForm, self).__init__(*args, **kwargs)
|
||||
super().__init__(*args, **kwargs)
|
||||
reload_queryset(self.fields)
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
|
||||
@@ -2,6 +2,7 @@ from django.db import models
|
||||
from django.forms import ValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from base.models import Company
|
||||
from base.horilla_company_manager import HorillaCompanyManager
|
||||
|
||||
# importing simple history
|
||||
from simple_history.models import HistoricalRecords
|
||||
@@ -17,8 +18,8 @@ class Period(models.Model):
|
||||
period_name = models.CharField(max_length=150, unique=True)
|
||||
start_date = models.DateField()
|
||||
end_date = models.DateField()
|
||||
company_id = models.ForeignKey(Company,null=True, editable=False, on_delete=models.PROTECT)
|
||||
objects = models.Manager()
|
||||
company_id = models.ManyToManyField(Company, blank=True, verbose_name=_("Company"))
|
||||
objects = HorillaCompanyManager()
|
||||
|
||||
def __str__(self):
|
||||
return self.period_name
|
||||
@@ -57,7 +58,7 @@ class EmployeeObjective(models.Model):
|
||||
)
|
||||
history = HorillaAuditLog(bases=[HorillaAuditInfo])
|
||||
archive = models.BooleanField(default=False, null=True, blank=True)
|
||||
objects = models.Manager()
|
||||
objects = HorillaCompanyManager("employee_id__employee_work_info__company_id")
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.employee_id.employee_first_name} - {self.objective}"
|
||||
@@ -83,7 +84,7 @@ class Comment(models.Model):
|
||||
)
|
||||
created_at = models.DateTimeField(auto_now_add=True, null=True, blank=True)
|
||||
history = HorillaAuditLog(excluded_fields=["comment"], bases=[HorillaAuditInfo])
|
||||
objects = models.Manager()
|
||||
objects = HorillaCompanyManager("employee_id__employee_work_info__company_id")
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.employee_id.employee_first_name} - {self.comment} "
|
||||
@@ -135,8 +136,8 @@ class EmployeeKeyResult(models.Model):
|
||||
start_date = models.DateField(null=True, blank=True)
|
||||
end_date = models.DateField(null=True, blank=True)
|
||||
history = HorillaAuditLog(bases=[HorillaAuditInfo])
|
||||
objects = HorillaCompanyManager("employee_id__employee_work_info__company_id")
|
||||
progress_percentage = models.IntegerField(null=True, blank=True, default=0)
|
||||
objects = models.Manager()
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.key_result} "
|
||||
@@ -159,8 +160,9 @@ class QuestionTemplate(models.Model):
|
||||
question_template = models.CharField(
|
||||
max_length=100, null=False, blank=False, unique=True
|
||||
)
|
||||
company_id = models.ForeignKey(Company,null=True, editable=False, on_delete=models.PROTECT)
|
||||
objects = models.Manager()
|
||||
company_id = models.ManyToManyField(Company, blank=True, verbose_name=_("Company"))
|
||||
|
||||
objects = HorillaCompanyManager()
|
||||
|
||||
def __str__(self):
|
||||
return self.question_template
|
||||
@@ -187,7 +189,7 @@ class Question(models.Model):
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
objects = models.Manager()
|
||||
objects = HorillaCompanyManager("template_id__company_id")
|
||||
|
||||
def __str__(self):
|
||||
return self.question
|
||||
@@ -207,7 +209,7 @@ class QuestionOptions(models.Model):
|
||||
option_b = models.CharField(max_length=250, null=True, blank=True)
|
||||
option_c = models.CharField(max_length=250, null=True, blank=True)
|
||||
option_d = models.CharField(max_length=250, null=True, blank=True)
|
||||
objects = models.Manager()
|
||||
objects = HorillaCompanyManager("question_id__template_id__company_id")
|
||||
|
||||
|
||||
class Feedback(models.Model):
|
||||
@@ -259,7 +261,7 @@ class Feedback(models.Model):
|
||||
EmployeeKeyResult,
|
||||
blank=True,
|
||||
)
|
||||
objects = models.Manager()
|
||||
objects = HorillaCompanyManager("employee_id__employee_work_info__company_id+")
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.employee_id.employee_first_name} - {self.review_cycle}"
|
||||
@@ -286,7 +288,7 @@ class Answer(models.Model):
|
||||
feedback_id = models.ForeignKey(
|
||||
Feedback, on_delete=models.PROTECT, related_name="feedback_answer"
|
||||
)
|
||||
objects = models.Manager()
|
||||
objects = HorillaCompanyManager("employee_id__employee_work_info__company_id")
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.employee_id.employee_first_name} - {self.answer}"
|
||||
@@ -311,4 +313,4 @@ class KeyResultFeedback(models.Model):
|
||||
blank=True,
|
||||
on_delete=models.DO_NOTHING,
|
||||
)
|
||||
objects = models.Manager()
|
||||
objects = HorillaCompanyManager("employee_id__employee_work_info__company_id")
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
{{question_update_form.question_template }}
|
||||
<!-- <span id="id_question_template_error" style="color: red;"></span> -->
|
||||
</div>
|
||||
<div class="oh-input__group">
|
||||
<label class="oh-input__label mt-2" for="keyTitle">{% trans "Company" %}</label>
|
||||
{{question_update_form.company_id }}
|
||||
<!-- <span id="id_question_template_error" style="color: red;"></span> -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="oh-modal__dialog-footer">
|
||||
<button type="submit" class="oh-btn oh-btn--secondary oh-btn--shadow ">
|
||||
|
||||
@@ -102,6 +102,10 @@
|
||||
{{form.question_template }}
|
||||
<ul class="errorlist" id="id_question_template_error" ></ul>
|
||||
</div>
|
||||
<div class="oh-input__group">
|
||||
<label class="oh-input__label mt-2" for="keyTitle">{% trans "Company" %}</label>
|
||||
{{form.company_id }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="oh-modal__dialog-footer">
|
||||
<button type="submit" class="oh-btn oh-btn--secondary oh-btn--shadow ">
|
||||
|
||||
@@ -39,6 +39,13 @@
|
||||
{{form.end_date.errors}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-sm-12 col-md-6 col-lg-12">
|
||||
<div class="oh-input__group">
|
||||
<label class="oh-input__label" for="keyType">{% trans "Company" %}</label>
|
||||
{{form.company_id}}
|
||||
{{form.company_id.errors}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -39,6 +39,13 @@
|
||||
{{form.end_date.errors}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-sm-12 col-md-6 col-lg-12">
|
||||
<div class="oh-input__group">
|
||||
<label class="oh-input__label" for="keyType">{% trans "Company" %}</label>
|
||||
{{form.company_id}}
|
||||
{{form.company_id.errors}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user