Files
ihrm/base/horilla_company_manager.py
Horilla 594f29b6ea Dev/v2.0 (#977)
* [FIX] BASE: Fixed the permissions in the settings page and updated the payroll permission

* [FIX] DOCKER: Issue with creating migration file for auth user model

* [FIX] EMPLOYEE : Document request view toggle issue fixes

* [FIX] ATTENDANCE: Fixed union of distinct querysets in attendance request

* [FIX] PAYROLL: Fixed reimbursement form excluded field issue

* [UPDT] WHATSAPP: Updated flow json version

* [UPDT] WHATSAPP: Updated meta_token from charfield to text field

* [UPDT] WHATSAPP: Updated whatsapp credential view url to CBV template view

* [FIX] WHATSAPP: Fixed issues in sending messages and added exception message if request failed

* [UPDT] RECRUITMENT: Formatted recruitment view page

* [UPDT] RECRUITMENT: Updated linkedin to check for integration enabled

* [FIX] SETTINGS: Fixed outlook issue on settings page

* [FIX] SETTINGS: Fixed outlook error in settings page

* [RMV] GENERAL: Remove unwanted console log messages

* [UPDT] HORILLA_THEME: Updated permission for ldap and Gmeet in settings page

* [RMV] GENERAL: Remove unwanted console log messages

* [UPDT] BASE: Index page updation

* [UPDT] WHATSAPP: Add whatsapp app to the installed_apps list

* [FIX] BASE: Fixed the permission issue in the general settings section

* [FIX] WHATSAPP: Fixed decorator issue and test message exception issue

* [RMV] GENERAL: Remove unwanted print statements

* [FIX] SETTINGS: Fixed typo in permission for Outlook

* [IMP] Remove formatting of migrations file from the pre-commit hooks

* [RMV] BASE: Unwanted variable from the chart

* [FIX] Fix the regex issue with exclusion of migrations files in the pre-commit config

* [FIX] EMPLOYEE: #964

* [FIX] EMPLOYEE: Employee import in v2

* [FIX] ATTENDANCE: Error handling for attendance out time initial setup

* [FIX] HORILLA_VIEWS: Fixed generic import modal id

* [UPDT] HORILLA_THEME: Updated login button styling and load database modal close button issue

* [FIX] HORILLA_THEME: Updated permission for linkedin in settings

* [FIX] HORILLA: Fixed import of app from base to django.apps

* [FIX] SETTINGS: Fixed outlook error in settings page

* [FIX] BASE: Restrict own records of employee profile edit fixes

* [FIX] LEAVE: Query optimization

* [FIX] BASE: Fixed database hit before apps loaded in company manager

* [UPDT] BASE: Moved EmployeeShiftDay creation logic from app ready() function to post_migrate signal

* [FIX] HELPDESK: Moved clean method from models to form and updated days remailning showing for resolved tickets (#949)

* [FIX] STYLE: Fixed yellow and yellowgreen row status color

* [UPDT] BASE: Added template tag for verbose name

* [FIX] BASE: General settings permission fixes

* [FIX] EMPLOYEE: Document request issue fixes while rejecting the document request

* [UPDT] PAYROLL: Updated filing status model

* [UPDT] NOTIFICATIONS: Updated notification model class Meta

* [UPDT] BASE: Updated form and company manager to prevent database call when django loading

* [UPDT] ONBOARDING: Fixed db hit on server loading

* [UPDT] PAYROLL: Fixed db hit on server loading

* [UPDT] PMS: Fixed db hit on server loading

* [UPDT] RECRUITMENT: Fixed db hit on server loading

* [FIX] OUTLOOK_AUTH: Fixed emaillog not showing for outlook emails (#959)

* [FIX] GENERIC: Fixed form submission issue when a validation error occured

* [FIX] ONBOARDING: Fixed filter instance in onboarding pipeline nav

* [FIX] RECRUITMENT: Fixed linkedIn error when creating recruitment(#973)

* [UPDT] Avoid formatting the __init__.py files from the migrations folder during pre-commit hook
2025-11-07 14:38:56 +05:30

135 lines
3.8 KiB
Python

"""
horilla_company_manager.py
"""
import logging
from typing import Coroutine, Sequence
from django.db import models
from django.db.models.query import QuerySet
from horilla.horilla_middlewares import _thread_locals
from horilla.signals import (
post_bulk_update,
post_model_clean,
pre_bulk_update,
pre_model_clean,
)
logger = logging.getLogger(__name__)
django_filter_update = QuerySet.update
def update(self, *args, **kwargs):
"""
Bulk Update
"""
# pre_update signal
request = getattr(_thread_locals, "request", None)
self.request = request
pre_bulk_update.send(sender=self.model, queryset=self, args=args, kwargs=kwargs)
result = django_filter_update(self, *args, **kwargs)
# post_update signal
post_bulk_update.send(sender=self.model, queryset=self, args=args, kwargs=kwargs)
return result
django_model_clean = models.Model.clean
def clean(self, *args, **kwargs):
"""
Method to override django clean and trigger to signals
"""
pre_model_clean.send(sender=self._meta.model, instance=self, **kwargs)
result = django_model_clean(self)
post_model_clean.send(sender=self._meta.model, instance=self, **kwargs)
return result
models.Model.clean = clean
setattr(QuerySet, "update", update)
class HorillaCompanyManager(models.Manager):
"""
HorillaCompanyManager
"""
def __init__(self, related_company_field=None, *args, **kwargs):
super().__init__(*args, **kwargs)
self.related_company_field = related_company_field
self.check_fields = [
"employee_id",
"requested_employee_id",
]
def get_queryset(self):
"""
get_queryset method
"""
queryset = super().get_queryset()
request = getattr(_thread_locals, "request", None)
selected_company = None
if request is not None:
selected_company = request.session.get("selected_company")
try:
queryset = (
queryset.filter(self.model.company_filter)
if selected_company != "all" and selected_company
else queryset
)
except Exception as e:
logger.error(e)
return queryset.distinct()
def all(self):
"""
Override the all() method
"""
queryset = []
try:
queryset = self.get_queryset()
model_name = queryset.model._meta.model_name
if model_name == "employee":
request = getattr(_thread_locals, "request", None)
if request:
active = (
True
if request.GET.get("is_active", True)
in ["unknown", "True", "true", True]
else False
)
queryset = queryset.filter(is_active=active)
elif model_name == "offboardingemployee":
return queryset
else:
for field in queryset.model._meta.fields:
if isinstance(field, models.ForeignKey):
if field.name in self.check_fields:
related_model_is_active_filter = {
f"{field.name}__is_active": True
}
queryset = queryset.filter(**related_model_is_active_filter)
except Exception as e:
logger.error(e)
return queryset
def filter(self, *args, **kwargs):
queryset = super().filter(*args, **kwargs)
setattr(_thread_locals, "queryset_filter", queryset)
return queryset
def entire(self):
"""
Fetch all datas from a model without applying any company filter.
"""
queryset = super().get_queryset()
return queryset # No filtering applied