diff --git a/base/methods.py b/base/methods.py
index aa8b8f188..b68d259e2 100644
--- a/base/methods.py
+++ b/base/methods.py
@@ -9,6 +9,7 @@ import pandas as pd
import pdfkit
from django.apps import apps
from django.conf import settings
+from django.contrib.auth.models import Group
from django.contrib.staticfiles import finders
from django.core.exceptions import ObjectDoesNotExist
from django.core.paginator import Paginator
@@ -27,6 +28,16 @@ from horilla.horilla_middlewares import _thread_locals
from horilla.horilla_settings import HORILLA_DATE_FORMATS, HORILLA_TIME_FORMATS
+def users_count(self):
+ """
+ Restrict Group users_count to selected company context
+ """
+ return Employee.objects.filter(employee_user_id__in=self.user_set.all()).count()
+
+
+Group.add_to_class("users_count", property(users_count))
+
+
def filtersubordinates(request, queryset, perm=None, field="employee_id"):
"""
This method is used to filter out subordinates queryset element.
diff --git a/base/templates/base/auth/group_lines.html b/base/templates/base/auth/group_lines.html
index 3b28dee50..bbb6dd831 100644
--- a/base/templates/base/auth/group_lines.html
+++ b/base/templates/base/auth/group_lines.html
@@ -15,7 +15,7 @@
- {% trans "Total" %} {{group.user_set.all|length}} {% trans "users in this group" %}
+ {% trans "Total" %} {{ group.users_count }} {% trans "users in this group" %}
{% if perms.auth.change_group or perms.auth.delete_group %}