Files
ihrm/base/filters.py

650 lines
20 KiB
Python
Raw Normal View History

2023-09-08 14:38:51 +05:30
"""
This module contains custom Django filters for filtering querysets related to Shift Requests,
Work Type Requests, Rotating Shift and Rotating Work Type Assign.
"""
import uuid
2023-05-10 15:06:57 +05:30
import django_filters
from django import forms
2025-03-18 13:58:44 +05:30
from django.db.models import Q
[IMP] Remove inter module dependency (#274) This commit introduces significant changes to the architecture of the Horilla HRMS system by decoupling interdependent modules. The following modifications were made: 1. **Module Independence**: Each module has been refactored to eliminate reliance on other modules, promoting a more modular and maintainable codebase. 2. **Refactored Imports and Dependencies**: Adjusted import statements and dependency injections to support independent module operation. 3. **Compatibility and Functionality**: Ensured that all modules are compatible with existing systems and maintain their intended functionality both independently and when integrated with other modules. These changes enhance the modularity, maintainability, and scalability of the Horilla HRMS, allowing developers to work on individual modules without affecting the entire system. Future development and deployment will be more efficient and less prone to issues arising from tightly coupled code. **NOTE** For existing Horilla users, if you face any issues during the migrations, please run the following command and try again the migrations. - `python3 manage.py makemigrations` - `python3 manage.py migrate base` - `python3 manage.py migrate` * [IMP] ASSET: Asset module dependency removal from other Horilla apps * [IMP] ATTENDANCE: Attendance module dependency removal from other Horilla apps * [IMP] BASE: Base module dependency removal from other Horilla apps * [IMP] EMPLOYEE: Employee module dependency removal from other Horilla apps * [IMP] HELPDESK: Helpdesk module dependency removal from other Horilla apps * [IMP] HORILLA AUDIT: Horilla Audit module dependency removal from other Horilla apps * [IMP] HORILLA CRUMBS: Horilla Crumbs module dependency removal from other Horilla apps * [IMP] HORILLA AUTOMATIONS: Horilla Automations module dependency removal from other Horilla apps * [IMP] HORILLA VIEWS: Horilla Views module dependency removal from other Horilla apps * [IMP] LEAVE: Leave module dependency removal from other Horilla apps * [IMP] OFFBOARDING: Offboarding module dependency removal from other Horilla apps * [IMP] ONBOARDING: Onboarding module dependency removal from other Horilla apps * [IMP] PMS: PMS module dependency removal from other Horilla apps * [IMP] PAYROLL: Payroll module dependency removal from other Horilla apps * [IMP] RECRUITMENT: Recruitment module dependency removal from other Horilla apps * [IMP] HORILLA: Dependency removal updates * [IMP] TEMPLATES: Dependency removal updates * [IMP] STATIC: Dependency removal updates * [IMP] HORILLA DOCUMENTS: Horilla Documents module dependency removal from other Horilla apps * [ADD] HORILLA: methods.py * [UPDT] HORILLA: Settings.py * [FIX] EMPLOYEE: About tab issue * Update horilla_settings.py * Remove dummy db init password
2024-08-05 14:22:44 +05:30
from django.utils.translation import gettext as __
2025-03-18 13:58:44 +05:30
from django_filters import CharFilter, DateFilter, FilterSet, filters
2023-09-08 14:38:51 +05:30
from base.models import (
2025-03-18 13:58:44 +05:30
Announcement,
AnnouncementView,
Company,
[IMP] Remove inter module dependency (#274) This commit introduces significant changes to the architecture of the Horilla HRMS system by decoupling interdependent modules. The following modifications were made: 1. **Module Independence**: Each module has been refactored to eliminate reliance on other modules, promoting a more modular and maintainable codebase. 2. **Refactored Imports and Dependencies**: Adjusted import statements and dependency injections to support independent module operation. 3. **Compatibility and Functionality**: Ensured that all modules are compatible with existing systems and maintain their intended functionality both independently and when integrated with other modules. These changes enhance the modularity, maintainability, and scalability of the Horilla HRMS, allowing developers to work on individual modules without affecting the entire system. Future development and deployment will be more efficient and less prone to issues arising from tightly coupled code. **NOTE** For existing Horilla users, if you face any issues during the migrations, please run the following command and try again the migrations. - `python3 manage.py makemigrations` - `python3 manage.py migrate base` - `python3 manage.py migrate` * [IMP] ASSET: Asset module dependency removal from other Horilla apps * [IMP] ATTENDANCE: Attendance module dependency removal from other Horilla apps * [IMP] BASE: Base module dependency removal from other Horilla apps * [IMP] EMPLOYEE: Employee module dependency removal from other Horilla apps * [IMP] HELPDESK: Helpdesk module dependency removal from other Horilla apps * [IMP] HORILLA AUDIT: Horilla Audit module dependency removal from other Horilla apps * [IMP] HORILLA CRUMBS: Horilla Crumbs module dependency removal from other Horilla apps * [IMP] HORILLA AUTOMATIONS: Horilla Automations module dependency removal from other Horilla apps * [IMP] HORILLA VIEWS: Horilla Views module dependency removal from other Horilla apps * [IMP] LEAVE: Leave module dependency removal from other Horilla apps * [IMP] OFFBOARDING: Offboarding module dependency removal from other Horilla apps * [IMP] ONBOARDING: Onboarding module dependency removal from other Horilla apps * [IMP] PMS: PMS module dependency removal from other Horilla apps * [IMP] PAYROLL: Payroll module dependency removal from other Horilla apps * [IMP] RECRUITMENT: Recruitment module dependency removal from other Horilla apps * [IMP] HORILLA: Dependency removal updates * [IMP] TEMPLATES: Dependency removal updates * [IMP] STATIC: Dependency removal updates * [IMP] HORILLA DOCUMENTS: Horilla Documents module dependency removal from other Horilla apps * [ADD] HORILLA: methods.py * [UPDT] HORILLA: Settings.py * [FIX] EMPLOYEE: About tab issue * Update horilla_settings.py * Remove dummy db init password
2024-08-05 14:22:44 +05:30
CompanyLeaves,
2025-03-18 13:58:44 +05:30
Department,
DynamicEmailConfiguration,
EmailLog,
EmployeeShift,
EmployeeShiftSchedule,
EmployeeType,
[IMP] Remove inter module dependency (#274) This commit introduces significant changes to the architecture of the Horilla HRMS system by decoupling interdependent modules. The following modifications were made: 1. **Module Independence**: Each module has been refactored to eliminate reliance on other modules, promoting a more modular and maintainable codebase. 2. **Refactored Imports and Dependencies**: Adjusted import statements and dependency injections to support independent module operation. 3. **Compatibility and Functionality**: Ensured that all modules are compatible with existing systems and maintain their intended functionality both independently and when integrated with other modules. These changes enhance the modularity, maintainability, and scalability of the Horilla HRMS, allowing developers to work on individual modules without affecting the entire system. Future development and deployment will be more efficient and less prone to issues arising from tightly coupled code. **NOTE** For existing Horilla users, if you face any issues during the migrations, please run the following command and try again the migrations. - `python3 manage.py makemigrations` - `python3 manage.py migrate base` - `python3 manage.py migrate` * [IMP] ASSET: Asset module dependency removal from other Horilla apps * [IMP] ATTENDANCE: Attendance module dependency removal from other Horilla apps * [IMP] BASE: Base module dependency removal from other Horilla apps * [IMP] EMPLOYEE: Employee module dependency removal from other Horilla apps * [IMP] HELPDESK: Helpdesk module dependency removal from other Horilla apps * [IMP] HORILLA AUDIT: Horilla Audit module dependency removal from other Horilla apps * [IMP] HORILLA CRUMBS: Horilla Crumbs module dependency removal from other Horilla apps * [IMP] HORILLA AUTOMATIONS: Horilla Automations module dependency removal from other Horilla apps * [IMP] HORILLA VIEWS: Horilla Views module dependency removal from other Horilla apps * [IMP] LEAVE: Leave module dependency removal from other Horilla apps * [IMP] OFFBOARDING: Offboarding module dependency removal from other Horilla apps * [IMP] ONBOARDING: Onboarding module dependency removal from other Horilla apps * [IMP] PMS: PMS module dependency removal from other Horilla apps * [IMP] PAYROLL: Payroll module dependency removal from other Horilla apps * [IMP] RECRUITMENT: Recruitment module dependency removal from other Horilla apps * [IMP] HORILLA: Dependency removal updates * [IMP] TEMPLATES: Dependency removal updates * [IMP] STATIC: Dependency removal updates * [IMP] HORILLA DOCUMENTS: Horilla Documents module dependency removal from other Horilla apps * [ADD] HORILLA: methods.py * [UPDT] HORILLA: Settings.py * [FIX] EMPLOYEE: About tab issue * Update horilla_settings.py * Remove dummy db init password
2024-08-05 14:22:44 +05:30
Holidays,
2025-03-18 13:58:44 +05:30
JobPosition,
MultipleApprovalCondition,
[IMP] Remove inter module dependency (#274) This commit introduces significant changes to the architecture of the Horilla HRMS system by decoupling interdependent modules. The following modifications were made: 1. **Module Independence**: Each module has been refactored to eliminate reliance on other modules, promoting a more modular and maintainable codebase. 2. **Refactored Imports and Dependencies**: Adjusted import statements and dependency injections to support independent module operation. 3. **Compatibility and Functionality**: Ensured that all modules are compatible with existing systems and maintain their intended functionality both independently and when integrated with other modules. These changes enhance the modularity, maintainability, and scalability of the Horilla HRMS, allowing developers to work on individual modules without affecting the entire system. Future development and deployment will be more efficient and less prone to issues arising from tightly coupled code. **NOTE** For existing Horilla users, if you face any issues during the migrations, please run the following command and try again the migrations. - `python3 manage.py makemigrations` - `python3 manage.py migrate base` - `python3 manage.py migrate` * [IMP] ASSET: Asset module dependency removal from other Horilla apps * [IMP] ATTENDANCE: Attendance module dependency removal from other Horilla apps * [IMP] BASE: Base module dependency removal from other Horilla apps * [IMP] EMPLOYEE: Employee module dependency removal from other Horilla apps * [IMP] HELPDESK: Helpdesk module dependency removal from other Horilla apps * [IMP] HORILLA AUDIT: Horilla Audit module dependency removal from other Horilla apps * [IMP] HORILLA CRUMBS: Horilla Crumbs module dependency removal from other Horilla apps * [IMP] HORILLA AUTOMATIONS: Horilla Automations module dependency removal from other Horilla apps * [IMP] HORILLA VIEWS: Horilla Views module dependency removal from other Horilla apps * [IMP] LEAVE: Leave module dependency removal from other Horilla apps * [IMP] OFFBOARDING: Offboarding module dependency removal from other Horilla apps * [IMP] ONBOARDING: Onboarding module dependency removal from other Horilla apps * [IMP] PMS: PMS module dependency removal from other Horilla apps * [IMP] PAYROLL: Payroll module dependency removal from other Horilla apps * [IMP] RECRUITMENT: Recruitment module dependency removal from other Horilla apps * [IMP] HORILLA: Dependency removal updates * [IMP] TEMPLATES: Dependency removal updates * [IMP] STATIC: Dependency removal updates * [IMP] HORILLA DOCUMENTS: Horilla Documents module dependency removal from other Horilla apps * [ADD] HORILLA: methods.py * [UPDT] HORILLA: Settings.py * [FIX] EMPLOYEE: About tab issue * Update horilla_settings.py * Remove dummy db init password
2024-08-05 14:22:44 +05:30
PenaltyAccounts,
2025-03-18 13:58:44 +05:30
RotatingShift,
2023-09-08 14:38:51 +05:30
RotatingShiftAssign,
2025-03-18 13:58:44 +05:30
RotatingWorkType,
2023-09-08 14:38:51 +05:30
RotatingWorkTypeAssign,
ShiftRequest,
2025-03-18 13:58:44 +05:30
WorkType,
WorkTypeRequest,
2023-09-08 14:38:51 +05:30
)
2025-03-18 13:58:44 +05:30
from horilla.filters import FilterSet, HorillaFilterSet, filter_by_name
2023-05-10 15:06:57 +05:30
2025-03-18 13:58:44 +05:30
class ShiftRequestFilter(HorillaFilterSet):
2023-09-08 14:38:51 +05:30
"""
Custom filter for Shift Requests.
"""
2023-05-10 15:06:57 +05:30
requested_date = django_filters.DateFilter(
2023-09-08 14:38:51 +05:30
field_name="requested_date", widget=forms.DateInput(attrs={"type": "date"})
2023-05-10 15:06:57 +05:30
)
requested_date__gte = django_filters.DateFilter(
2023-09-08 14:38:51 +05:30
field_name="requested_date",
lookup_expr="gte",
widget=forms.DateInput(attrs={"type": "date"}),
2023-05-10 15:06:57 +05:30
)
requested_date__lte = django_filters.DateFilter(
2023-09-08 14:38:51 +05:30
field_name="requested_date",
lookup_expr="lte",
widget=forms.DateInput(attrs={"type": "date"}),
2023-05-10 15:06:57 +05:30
)
search = CharFilter(method=filter_by_name)
2025-03-18 13:58:44 +05:30
requested = django_filters.BooleanFilter(
method="filter_requested", label="Requested?"
)
2023-05-10 15:06:57 +05:30
class Meta:
2023-09-08 14:38:51 +05:30
"""
A nested class that specifies the model and fields for the filter.
"""
fields = "__all__"
2023-05-10 15:06:57 +05:30
model = ShiftRequest
fields = [
2024-01-31 12:01:20 +05:30
"id",
2023-09-08 14:38:51 +05:30
"employee_id",
"requested_date",
"previous_shift_id",
"shift_id",
"requested_till",
2023-09-08 14:38:51 +05:30
"approved",
"canceled",
"employee_id__employee_first_name",
"employee_id__employee_last_name",
"employee_id__is_active",
"employee_id__gender",
"employee_id__employee_work_info__job_position_id",
"employee_id__employee_work_info__department_id",
"employee_id__employee_work_info__work_type_id",
"employee_id__employee_work_info__employee_type_id",
"employee_id__employee_work_info__job_role_id",
"employee_id__employee_work_info__reporting_manager_id",
"employee_id__employee_work_info__company_id",
"employee_id__employee_work_info__shift_id",
2023-05-10 15:06:57 +05:30
]
def __init__(self, data=None, queryset=None, *, request=None, prefix=None):
super().__init__(data=data, queryset=queryset, request=request, prefix=prefix)
for field in self.form.fields.keys():
self.form.fields[field].widget.attrs["id"] = f"{uuid.uuid4()}"
2025-03-18 13:58:44 +05:30
def filter_requested(self, queryset, name, value):
"""
Filters the queryset to return entries where 'approved' is False and 'canceled' is False.
"""
if value:
return queryset.filter(approved=False, canceled=False)
return queryset
2023-05-10 15:06:57 +05:30
2025-03-18 13:58:44 +05:30
class WorkTypeRequestFilter(HorillaFilterSet):
2023-09-08 14:38:51 +05:30
"""
Custom filter for Work Type Requests.
"""
2023-05-10 15:06:57 +05:30
requested_date = django_filters.DateFilter(
2023-09-08 14:38:51 +05:30
field_name="requested_date", widget=forms.DateInput(attrs={"type": "date"})
2023-05-10 15:06:57 +05:30
)
requested_date__gte = django_filters.DateFilter(
2023-09-08 14:38:51 +05:30
field_name="requested_till",
lookup_expr="gte",
widget=forms.DateInput(attrs={"type": "date"}),
2023-05-10 15:06:57 +05:30
)
requested_date__lte = django_filters.DateFilter(
2023-09-08 14:38:51 +05:30
field_name="requested_till",
lookup_expr="lte",
widget=forms.DateInput(attrs={"type": "date"}),
2023-05-10 15:06:57 +05:30
)
2025-03-18 13:58:44 +05:30
requested = django_filters.BooleanFilter(
method="filter_by_requested", label="Requested"
)
2023-05-10 15:06:57 +05:30
search = CharFilter(method=filter_by_name)
2023-09-08 14:38:51 +05:30
2023-05-10 15:06:57 +05:30
class Meta:
2023-09-08 14:38:51 +05:30
"""
A nested class that specifies the model and fields for the filter.
"""
fields = "__all__"
2023-05-10 15:06:57 +05:30
model = WorkTypeRequest
fields = [
"id",
2023-09-08 14:38:51 +05:30
"employee_id",
"requested_date",
"previous_work_type_id",
"approved",
"work_type_id",
"canceled",
"employee_id__employee_first_name",
"employee_id__employee_last_name",
"employee_id__is_active",
"employee_id__gender",
"employee_id__employee_work_info__job_position_id",
"employee_id__employee_work_info__department_id",
"employee_id__employee_work_info__work_type_id",
"employee_id__employee_work_info__employee_type_id",
"employee_id__employee_work_info__job_role_id",
"employee_id__employee_work_info__reporting_manager_id",
"employee_id__employee_work_info__company_id",
"employee_id__employee_work_info__shift_id",
2023-05-10 15:06:57 +05:30
]
2023-09-08 14:38:51 +05:30
def __init__(self, data=None, queryset=None, *, request=None, prefix=None):
super().__init__(data=data, queryset=queryset, request=request, prefix=prefix)
for field in self.form.fields.keys():
self.form.fields[field].widget.attrs["id"] = f"{uuid.uuid4()}"
2025-03-18 13:58:44 +05:30
def filter_by_requested(self, queryset, name, value):
"""
Filters the queryset to return entries where 'approved' is False and 'canceled' is False.
"""
if value:
return queryset.filter(approved=False, canceled=False)
return queryset
2023-05-10 15:06:57 +05:30
2025-03-18 13:58:44 +05:30
class RotatingShiftAssignFilters(HorillaFilterSet):
2023-09-08 14:38:51 +05:30
"""
Custom filter for Rotating Shift Assign.
"""
2023-05-10 15:06:57 +05:30
search = CharFilter(method=filter_by_name)
next_change_date = django_filters.DateFilter(
2023-09-08 14:38:51 +05:30
field_name="next_change_date", widget=forms.DateInput(attrs={"type": "date"})
2023-05-10 15:06:57 +05:30
)
start_date = django_filters.DateFilter(
2023-09-08 14:38:51 +05:30
field_name="start_date", widget=forms.DateInput(attrs={"type": "date"})
2023-05-10 15:06:57 +05:30
)
2023-09-08 14:38:51 +05:30
2023-05-10 15:06:57 +05:30
class Meta:
2023-09-08 14:38:51 +05:30
"""
A nested class that specifies the model and fields for the filter.
"""
fields = "__all__"
2023-05-10 15:06:57 +05:30
model = RotatingShiftAssign
fields = [
2023-09-08 14:38:51 +05:30
"employee_id",
"rotating_shift_id",
"next_change_date",
"start_date",
"based_on",
"rotate_after_day",
"rotate_every_weekend",
"rotate_every",
"current_shift",
"next_shift",
"is_active",
"employee_id__employee_work_info__job_position_id",
"employee_id__employee_work_info__department_id",
"employee_id__employee_work_info__work_type_id",
"employee_id__employee_work_info__employee_type_id",
"employee_id__employee_work_info__job_role_id",
"employee_id__employee_work_info__reporting_manager_id",
"employee_id__employee_work_info__company_id",
"employee_id__employee_work_info__shift_id",
2023-05-10 15:06:57 +05:30
]
2025-03-18 13:58:44 +05:30
class RotatingWorkTypeAssignFilter(HorillaFilterSet):
2023-09-08 14:38:51 +05:30
"""
Custom filter for Rotating Work Type Assign.
"""
2023-05-10 15:06:57 +05:30
search = CharFilter(method=filter_by_name)
next_change_date = django_filters.DateFilter(
2023-09-08 14:38:51 +05:30
field_name="next_change_date", widget=forms.DateInput(attrs={"type": "date"})
2023-05-10 15:06:57 +05:30
)
start_date = django_filters.DateFilter(
2023-09-08 14:38:51 +05:30
field_name="start_date", widget=forms.DateInput(attrs={"type": "date"})
2023-05-10 15:06:57 +05:30
)
2023-09-08 14:38:51 +05:30
2023-05-10 15:06:57 +05:30
class Meta:
2023-09-08 14:38:51 +05:30
"""
A nested class that specifies the model and fields for the filter.
"""
fields = "__all__"
2023-05-10 15:06:57 +05:30
model = RotatingWorkTypeAssign
fields = [
2023-09-08 14:38:51 +05:30
"employee_id",
"rotating_work_type_id",
"next_change_date",
"start_date",
"based_on",
"rotate_after_day",
"rotate_every_weekend",
"rotate_every",
"current_work_type",
"next_work_type",
"is_active",
"employee_id__employee_work_info__job_position_id",
"employee_id__employee_work_info__department_id",
"employee_id__employee_work_info__work_type_id",
"employee_id__employee_work_info__employee_type_id",
"employee_id__employee_work_info__job_role_id",
"employee_id__employee_work_info__reporting_manager_id",
"employee_id__employee_work_info__company_id",
"employee_id__employee_work_info__shift_id",
]
class ShiftRequestReGroup:
"""
Class to keep the field name for group by option
"""
fields = [
("", "Select"),
("employee_id", "Employee"),
("shift_id", "Requested Shift"),
("previous_shift_id", "Current Shift"),
("requested_date", "Requested Date"),
]
class WorkTypeRequestReGroup:
"""
Class to keep the field name for group by option
"""
fields = [
("", "Select"),
("employee_id", "Employee"),
("work_type_id", "Requested Work Type"),
("previous_work_type_id", "Current Work Type"),
("requested_date", "Requested Date"),
("employee_id__employee_work_info__department_id", "Department"),
("employee_id__employee_work_info__job_position_id", "Job Position"),
("employee_id__employee_work_info__reporting_manager_id", "Reporting Manager"),
]
class RotatingWorkTypeRequestReGroup:
"""
Class to keep the field name for group by option
"""
fields = [
("", "Select"),
("employee_id", "Employee"),
("rotating_work_type_id", "Rotating Work Type"),
("current_work_type", "Current Work Type"),
("based_on", "Based On"),
("employee_id__employee_work_info__department_id", "Department"),
("employee_id__employee_work_info__job_role_id", "Job Role"),
("employee_id__employee_work_info__reporting_manager_id", "Reporting Manager"),
]
class RotatingShiftRequestReGroup:
"""
Class to keep the field name for group by option
"""
fields = [
("", "Select"),
("employee_id", "Employee"),
("rotating_shift_id", "Rotating Shift"),
("based_on", "Based On"),
("employee_id__employee_work_info__department_id", "Department"),
("employee_id__employee_work_info__job_role_id", "Job Role"),
("employee_id__employee_work_info__reporting_manager_id", "Reporting Manager"),
]
[IMP] Remove inter module dependency (#274) This commit introduces significant changes to the architecture of the Horilla HRMS system by decoupling interdependent modules. The following modifications were made: 1. **Module Independence**: Each module has been refactored to eliminate reliance on other modules, promoting a more modular and maintainable codebase. 2. **Refactored Imports and Dependencies**: Adjusted import statements and dependency injections to support independent module operation. 3. **Compatibility and Functionality**: Ensured that all modules are compatible with existing systems and maintain their intended functionality both independently and when integrated with other modules. These changes enhance the modularity, maintainability, and scalability of the Horilla HRMS, allowing developers to work on individual modules without affecting the entire system. Future development and deployment will be more efficient and less prone to issues arising from tightly coupled code. **NOTE** For existing Horilla users, if you face any issues during the migrations, please run the following command and try again the migrations. - `python3 manage.py makemigrations` - `python3 manage.py migrate base` - `python3 manage.py migrate` * [IMP] ASSET: Asset module dependency removal from other Horilla apps * [IMP] ATTENDANCE: Attendance module dependency removal from other Horilla apps * [IMP] BASE: Base module dependency removal from other Horilla apps * [IMP] EMPLOYEE: Employee module dependency removal from other Horilla apps * [IMP] HELPDESK: Helpdesk module dependency removal from other Horilla apps * [IMP] HORILLA AUDIT: Horilla Audit module dependency removal from other Horilla apps * [IMP] HORILLA CRUMBS: Horilla Crumbs module dependency removal from other Horilla apps * [IMP] HORILLA AUTOMATIONS: Horilla Automations module dependency removal from other Horilla apps * [IMP] HORILLA VIEWS: Horilla Views module dependency removal from other Horilla apps * [IMP] LEAVE: Leave module dependency removal from other Horilla apps * [IMP] OFFBOARDING: Offboarding module dependency removal from other Horilla apps * [IMP] ONBOARDING: Onboarding module dependency removal from other Horilla apps * [IMP] PMS: PMS module dependency removal from other Horilla apps * [IMP] PAYROLL: Payroll module dependency removal from other Horilla apps * [IMP] RECRUITMENT: Recruitment module dependency removal from other Horilla apps * [IMP] HORILLA: Dependency removal updates * [IMP] TEMPLATES: Dependency removal updates * [IMP] STATIC: Dependency removal updates * [IMP] HORILLA DOCUMENTS: Horilla Documents module dependency removal from other Horilla apps * [ADD] HORILLA: methods.py * [UPDT] HORILLA: Settings.py * [FIX] EMPLOYEE: About tab issue * Update horilla_settings.py * Remove dummy db init password
2024-08-05 14:22:44 +05:30
2025-03-18 13:58:44 +05:30
class MultipleApprovalConditionFilter(HorillaFilterSet):
search = django_filters.CharFilter(method="search_method")
class Meta:
model = MultipleApprovalCondition
fields = [
"department",
]
def search_method(self, queryset, _, value):
"""
This method is used to search department
"""
return (queryset.filter(department__department__icontains=value)).distinct()
class EmployeeShiftFilter(FilterSet):
search = django_filters.CharFilter(
field_name="employee_shift", lookup_expr="icontains"
)
class Meta:
model = EmployeeShift
fields = [
"employee_shift",
]
class EmployeeShiftScheduleFilter(FilterSet):
search = django_filters.CharFilter(field_name="day__day", lookup_expr="icontains")
class Meta:
model = EmployeeShiftSchedule
fields = []
class RotatingShiftFilter(HorillaFilterSet):
# search = django_filters.CharFilter(
# field_name="name", lookup_expr="icontains"
# )
search = django_filters.CharFilter(method="search_method")
class Meta:
model = RotatingShift
fields = ["name", "shift1", "shift2"]
def search_method(self, queryset, _, value):
"""
This method is used to search employees and objective
"""
return (
queryset.filter(name__icontains=value)
| queryset.filter(shift1__employee_shift__icontains=value)
| queryset.filter(shift2__employee_shift__icontains=value)
).distinct()
class DepartmentViewFilter(HorillaFilterSet):
search = django_filters.CharFilter(method="filter_by_all_fields")
class Meta:
model = Department
fields = [
"department",
]
def filter_by_all_fields(self, queryset, name, value):
return queryset.filter(
Q(department__icontains=value)
| Q(job_position__job_position__icontains=value)
).distinct()
class WorkTypeFilter(HorillaFilterSet):
search = django_filters.CharFilter(field_name="work_type", lookup_expr="icontains")
class Meta:
model = WorkType
fields = [
"work_type",
]
class RotatingWorkTypeFilter(HorillaFilterSet):
search = django_filters.CharFilter(method="search_method")
def search_method(self, queryset, _, value):
"""
This method is used to search employees and objective
"""
return (
queryset.filter(name__icontains=value)
| queryset.filter(work_type1__work_type__icontains=value)
| queryset.filter(work_type2__work_type__icontains=value)
).distinct()
class Meta:
model = RotatingWorkType
fields = ["name", "work_type1", "work_type2"]
class EmployeeTypeFilter(FilterSet):
search = django_filters.CharFilter(
field_name="employee_type", lookup_expr="icontains"
)
class Meta:
model = EmployeeType
fields = [
"employee_type",
]
class JobRoleFilter(HorillaFilterSet):
search = django_filters.CharFilter(method="filter_by_all_fields")
class Meta:
model = JobPosition
fields = [
"job_position",
]
def filter_by_all_fields(self, queryset, name, value):
return queryset.filter(
Q(job_position__icontains=value) | Q(jobrole__job_role__icontains=value)
).distinct()
class CompanyFilter(FilterSet):
search = CharFilter(method="search_method")
def search_method(self, queryset, _, value):
"""
This method is used to search company and objective
"""
return (
queryset.filter(company__icontains=value)
| queryset.filter(hq__icontains=value)
| queryset.filter(address__icontains=value)
| queryset.filter(country__icontains=value)
| queryset.filter(state__icontains=value)
| queryset.filter(city__icontains=value)
| queryset.filter(zip__icontains=value)
).distinct()
class Meta:
model = Company
fields = ["company", "hq", "address", "country", "state", "city", "zip"]
class MailServerFilter(HorillaFilterSet):
search = django_filters.CharFilter(method="search_method")
class Meta:
model = DynamicEmailConfiguration
fields = ["username"]
def search_method(self, queryset, _, value):
"""
This method is used to mail server
"""
return ((queryset.filter(username__icontains=value))).distinct()
class HolidayFilter(HorillaFilterSet):
[IMP] Remove inter module dependency (#274) This commit introduces significant changes to the architecture of the Horilla HRMS system by decoupling interdependent modules. The following modifications were made: 1. **Module Independence**: Each module has been refactored to eliminate reliance on other modules, promoting a more modular and maintainable codebase. 2. **Refactored Imports and Dependencies**: Adjusted import statements and dependency injections to support independent module operation. 3. **Compatibility and Functionality**: Ensured that all modules are compatible with existing systems and maintain their intended functionality both independently and when integrated with other modules. These changes enhance the modularity, maintainability, and scalability of the Horilla HRMS, allowing developers to work on individual modules without affecting the entire system. Future development and deployment will be more efficient and less prone to issues arising from tightly coupled code. **NOTE** For existing Horilla users, if you face any issues during the migrations, please run the following command and try again the migrations. - `python3 manage.py makemigrations` - `python3 manage.py migrate base` - `python3 manage.py migrate` * [IMP] ASSET: Asset module dependency removal from other Horilla apps * [IMP] ATTENDANCE: Attendance module dependency removal from other Horilla apps * [IMP] BASE: Base module dependency removal from other Horilla apps * [IMP] EMPLOYEE: Employee module dependency removal from other Horilla apps * [IMP] HELPDESK: Helpdesk module dependency removal from other Horilla apps * [IMP] HORILLA AUDIT: Horilla Audit module dependency removal from other Horilla apps * [IMP] HORILLA CRUMBS: Horilla Crumbs module dependency removal from other Horilla apps * [IMP] HORILLA AUTOMATIONS: Horilla Automations module dependency removal from other Horilla apps * [IMP] HORILLA VIEWS: Horilla Views module dependency removal from other Horilla apps * [IMP] LEAVE: Leave module dependency removal from other Horilla apps * [IMP] OFFBOARDING: Offboarding module dependency removal from other Horilla apps * [IMP] ONBOARDING: Onboarding module dependency removal from other Horilla apps * [IMP] PMS: PMS module dependency removal from other Horilla apps * [IMP] PAYROLL: Payroll module dependency removal from other Horilla apps * [IMP] RECRUITMENT: Recruitment module dependency removal from other Horilla apps * [IMP] HORILLA: Dependency removal updates * [IMP] TEMPLATES: Dependency removal updates * [IMP] STATIC: Dependency removal updates * [IMP] HORILLA DOCUMENTS: Horilla Documents module dependency removal from other Horilla apps * [ADD] HORILLA: methods.py * [UPDT] HORILLA: Settings.py * [FIX] EMPLOYEE: About tab issue * Update horilla_settings.py * Remove dummy db init password
2024-08-05 14:22:44 +05:30
"""
Filter class for Holidays model.
This filter allows searching Holidays objects based on name and date range.
"""
search = filters.CharFilter(field_name="name", lookup_expr="icontains")
from_date = DateFilter(
field_name="start_date",
lookup_expr="gte",
widget=forms.DateInput(attrs={"type": "date"}),
)
to_date = DateFilter(
field_name="end_date",
lookup_expr="lte",
widget=forms.DateInput(attrs={"type": "date"}),
)
start_date = DateFilter(
field_name="start_date",
lookup_expr="exact",
widget=forms.DateInput(attrs={"type": "date"}),
)
end_date = DateFilter(
field_name="end_date",
lookup_expr="exact",
widget=forms.DateInput(attrs={"type": "date"}),
)
class Meta:
"""
Meta class defines the model and fields to filter
"""
model = Holidays
fields = {
"recurring": ["exact"],
}
def __init__(self, data=None, queryset=None, *, request=None, prefix=None):
super().__init__(data=data, queryset=queryset, request=request, prefix=prefix)
for field in self.form.fields.keys():
self.form.fields[field].widget.attrs["id"] = f"{uuid.uuid4()}"
2025-06-04 11:21:22 +05:30
self.form.fields["from_date"].label = (
f"{self.Meta.model()._meta.get_field('start_date').verbose_name} From"
)
self.form.fields["to_date"].label = (
f"{self.Meta.model()._meta.get_field('end_date').verbose_name} Till"
)
[IMP] Remove inter module dependency (#274) This commit introduces significant changes to the architecture of the Horilla HRMS system by decoupling interdependent modules. The following modifications were made: 1. **Module Independence**: Each module has been refactored to eliminate reliance on other modules, promoting a more modular and maintainable codebase. 2. **Refactored Imports and Dependencies**: Adjusted import statements and dependency injections to support independent module operation. 3. **Compatibility and Functionality**: Ensured that all modules are compatible with existing systems and maintain their intended functionality both independently and when integrated with other modules. These changes enhance the modularity, maintainability, and scalability of the Horilla HRMS, allowing developers to work on individual modules without affecting the entire system. Future development and deployment will be more efficient and less prone to issues arising from tightly coupled code. **NOTE** For existing Horilla users, if you face any issues during the migrations, please run the following command and try again the migrations. - `python3 manage.py makemigrations` - `python3 manage.py migrate base` - `python3 manage.py migrate` * [IMP] ASSET: Asset module dependency removal from other Horilla apps * [IMP] ATTENDANCE: Attendance module dependency removal from other Horilla apps * [IMP] BASE: Base module dependency removal from other Horilla apps * [IMP] EMPLOYEE: Employee module dependency removal from other Horilla apps * [IMP] HELPDESK: Helpdesk module dependency removal from other Horilla apps * [IMP] HORILLA AUDIT: Horilla Audit module dependency removal from other Horilla apps * [IMP] HORILLA CRUMBS: Horilla Crumbs module dependency removal from other Horilla apps * [IMP] HORILLA AUTOMATIONS: Horilla Automations module dependency removal from other Horilla apps * [IMP] HORILLA VIEWS: Horilla Views module dependency removal from other Horilla apps * [IMP] LEAVE: Leave module dependency removal from other Horilla apps * [IMP] OFFBOARDING: Offboarding module dependency removal from other Horilla apps * [IMP] ONBOARDING: Onboarding module dependency removal from other Horilla apps * [IMP] PMS: PMS module dependency removal from other Horilla apps * [IMP] PAYROLL: Payroll module dependency removal from other Horilla apps * [IMP] RECRUITMENT: Recruitment module dependency removal from other Horilla apps * [IMP] HORILLA: Dependency removal updates * [IMP] TEMPLATES: Dependency removal updates * [IMP] STATIC: Dependency removal updates * [IMP] HORILLA DOCUMENTS: Horilla Documents module dependency removal from other Horilla apps * [ADD] HORILLA: methods.py * [UPDT] HORILLA: Settings.py * [FIX] EMPLOYEE: About tab issue * Update horilla_settings.py * Remove dummy db init password
2024-08-05 14:22:44 +05:30
2025-03-18 13:58:44 +05:30
class CompanyLeaveFilter(HorillaFilterSet):
[IMP] Remove inter module dependency (#274) This commit introduces significant changes to the architecture of the Horilla HRMS system by decoupling interdependent modules. The following modifications were made: 1. **Module Independence**: Each module has been refactored to eliminate reliance on other modules, promoting a more modular and maintainable codebase. 2. **Refactored Imports and Dependencies**: Adjusted import statements and dependency injections to support independent module operation. 3. **Compatibility and Functionality**: Ensured that all modules are compatible with existing systems and maintain their intended functionality both independently and when integrated with other modules. These changes enhance the modularity, maintainability, and scalability of the Horilla HRMS, allowing developers to work on individual modules without affecting the entire system. Future development and deployment will be more efficient and less prone to issues arising from tightly coupled code. **NOTE** For existing Horilla users, if you face any issues during the migrations, please run the following command and try again the migrations. - `python3 manage.py makemigrations` - `python3 manage.py migrate base` - `python3 manage.py migrate` * [IMP] ASSET: Asset module dependency removal from other Horilla apps * [IMP] ATTENDANCE: Attendance module dependency removal from other Horilla apps * [IMP] BASE: Base module dependency removal from other Horilla apps * [IMP] EMPLOYEE: Employee module dependency removal from other Horilla apps * [IMP] HELPDESK: Helpdesk module dependency removal from other Horilla apps * [IMP] HORILLA AUDIT: Horilla Audit module dependency removal from other Horilla apps * [IMP] HORILLA CRUMBS: Horilla Crumbs module dependency removal from other Horilla apps * [IMP] HORILLA AUTOMATIONS: Horilla Automations module dependency removal from other Horilla apps * [IMP] HORILLA VIEWS: Horilla Views module dependency removal from other Horilla apps * [IMP] LEAVE: Leave module dependency removal from other Horilla apps * [IMP] OFFBOARDING: Offboarding module dependency removal from other Horilla apps * [IMP] ONBOARDING: Onboarding module dependency removal from other Horilla apps * [IMP] PMS: PMS module dependency removal from other Horilla apps * [IMP] PAYROLL: Payroll module dependency removal from other Horilla apps * [IMP] RECRUITMENT: Recruitment module dependency removal from other Horilla apps * [IMP] HORILLA: Dependency removal updates * [IMP] TEMPLATES: Dependency removal updates * [IMP] STATIC: Dependency removal updates * [IMP] HORILLA DOCUMENTS: Horilla Documents module dependency removal from other Horilla apps * [ADD] HORILLA: methods.py * [UPDT] HORILLA: Settings.py * [FIX] EMPLOYEE: About tab issue * Update horilla_settings.py * Remove dummy db init password
2024-08-05 14:22:44 +05:30
"""
Filter class for CompanyLeaves model.
This filter allows searching CompanyLeaves objects based on
name, week day and based_on_week choices.
"""
name = filters.CharFilter(field_name="based_on_week_day", lookup_expr="icontains")
search = filters.CharFilter(method="filter_week_day")
class Meta:
""" "
Meta class defines the model and fields to filter
"""
model = CompanyLeaves
fields = {
"based_on_week": ["exact"],
"based_on_week_day": ["exact"],
}
def filter_week_day(self, queryset, _, value):
week_qry = CompanyLeaves.objects.none()
weekday_values = []
week_values = []
WEEK_DAYS = [
("0", __("Monday")),
("1", __("Tuesday")),
("2", __("Wednesday")),
("3", __("Thursday")),
("4", __("Friday")),
("5", __("Saturday")),
("6", __("Sunday")),
]
WEEKS = [
(None, __("All")),
("0", __("First Week")),
("1", __("Second Week")),
("2", __("Third Week")),
("3", __("Fourth Week")),
("4", __("Fifth Week")),
]
for day_value, day_name in WEEK_DAYS:
if value.lower() in day_name.lower():
weekday_values.append(day_value)
for day_value, day_name in WEEKS:
if value.lower() in day_name.lower() and value.lower() != __("All").lower():
week_values.append(day_value)
week_qry = queryset.filter(based_on_week__in=week_values)
elif value.lower() in __("All").lower():
week_qry = queryset.filter(based_on_week__isnull=True)
return queryset.filter(based_on_week_day__in=weekday_values) | week_qry
class PenaltyFilter(FilterSet):
"""
PenaltyFilter
"""
class Meta:
model = PenaltyAccounts
fields = "__all__"
2025-03-18 13:58:44 +05:30
class MailLogFilter(HorillaFilterSet):
search = django_filters.CharFilter(field_name="subject", lookup_expr="icontains")
class Meta:
model = EmailLog
fields = "__all__"
class AnnouncementFilter(HorillaFilterSet):
search = django_filters.CharFilter(field_name="title", lookup_expr="icontains")
class Meta:
model = Announcement
fields = "__all__"
class AnnouncementViewFilter(HorillaFilterSet):
search = django_filters.CharFilter(
field_name="announcement", lookup_expr="icontains"
)
class Meta:
model = AnnouncementView
fields = "__all__"