diff --git a/base/methods.py b/base/methods.py index c95e0e9e9..46f71831b 100644 --- a/base/methods.py +++ b/base/methods.py @@ -552,6 +552,8 @@ def reload_queryset(fields): "Employee": {"is_active": True}, "Candidate": {"is_active": True} if apps.is_installed("recruitment") else None, } + request = getattr(_thread_locals, "request") + selected_company = request.session.get("selected_company") for field in fields.values(): if isinstance(field, ModelChoiceField): @@ -559,6 +561,10 @@ def reload_queryset(fields): filter_criteria = model_filters.get(model_name) if filter_criteria is not None: field.queryset = field.queryset.model.objects.filter(**filter_criteria) + elif selected_company and not selected_company == "all": + field.queryset = field.queryset.model.objects.filter( + id=selected_company + ) else: field.queryset = field.queryset.model.objects.all() diff --git a/base/models.py b/base/models.py index b2ee6a99b..6903bf47f 100644 --- a/base/models.py +++ b/base/models.py @@ -1707,7 +1707,7 @@ class CompanyLeaves(HorillaModel): ) based_on_week_day = models.CharField(max_length=100, choices=WEEK_DAYS) company_id = models.ForeignKey(Company, null=True, on_delete=models.PROTECT) - objects = HorillaCompanyManager(related_company_field="company_id") + objects = HorillaCompanyManager() class Meta: unique_together = ("based_on_week", "based_on_week_day") diff --git a/base/templates/holiday/holiday_update_form.html b/base/templates/holiday/holiday_update_form.html index dd560d404..228b0fba1 100644 --- a/base/templates/holiday/holiday_update_form.html +++ b/base/templates/holiday/holiday_update_form.html @@ -40,8 +40,6 @@