Skip to content

Commit

Permalink
Merge branch 'horilla-opensource:1.0' into Production
Browse files Browse the repository at this point in the history
  • Loading branch information
Guhan-SenSam authored Jun 16, 2024
2 parents fb81c7d + bd1516a commit 137b5d9
Show file tree
Hide file tree
Showing 27 changed files with 429 additions and 151 deletions.
6 changes: 3 additions & 3 deletions asset/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
{
"menu": trans("Dashboard"),
"redirect": reverse("asset-dashboard"),
"accessability": "asset.sidebar.dashboard_accessability",
"accessibility": "asset.sidebar.dashboard_accessibility",
},
{
"menu": trans("Asset View"),
"redirect": reverse("asset-category-view"),
"accessability": "asset.sidebar.dashboard_accessability",
"accessibility": "asset.sidebar.dashboard_accessibility",
},
{
"menu": trans("Request and Allocation"),
Expand All @@ -30,5 +30,5 @@
]


def dashboard_accessability(request, submenu, user_perms, *args, **kwargs):
def dashboard_accessibility(request, submenu, user_perms, *args, **kwargs):
return request.user.has_perm("asset.view_assetcategory")
6 changes: 3 additions & 3 deletions asset/templates/asset_history/asset_history_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div data-cell-index="1" data-cell-title="{% trans "Asset" %}" class="oh-sticky-table__th {% if request.sort_option.order == '-asset_id__asset_name' %}arrow-up {% elif request.sort_option.order == 'asset_id__asset_name' %}arrow-down {% else %}arrow-up-down {% endif %}" hx-get="{% url 'asset-history-search' %}?{{pd}}&sortby=asset_id__asset_name" hx-target="#historyTable">{% trans "Asset" %}</div>
<div class="oh-sticky-table__th {% if request.sort_option.order == '-assigned_to_employee_id__employee_first_name' %}arrow-up {% elif request.sort_option.order == 'assigned_to_employee_id__employee_first_name' %}arrow-down {% else %}arrow-up-down {% endif %}" hx-get="{% url 'asset-history-search' %}?{{pd}}&sortby=assigned_to_employee_id__employee_first_name" hx-target="#historyTable">{% trans "Employee" %}</div>
<div data-cell-index="2" data-cell-title="{% trans "Assigned Date" %}" class="oh-sticky-table__th {% if request.sort_option.order == '-assigned_date' %}arrow-up {% elif request.sort_option.order == 'assigned_date' %}arrow-down {% else %}arrow-up-down {% endif %}" hx-get="{% url 'asset-history-search' %}?{{pd}}&sortby=assigned_date" hx-target="#historyTable">{% trans "Assigned Date" %}</div>
<div data-cell-index="3" data-cell-title="{% trans "Hours to Validate" %}" class="oh-sticky-table__th {% if request.sort_option.order == '-return_date' %}arrow-up {% elif request.sort_option.order == 'return_date' %}arrow-down {% else %}arrow-up-down {% endif %}" hx-get="{% url 'asset-history-search' %}?{{pd}}&sortby=return_date" hx-target="#historyTable">{% trans "Returned Date" %}</div>
<div data-cell-index="3" data-cell-title="{% trans "Returned date" %}" class="oh-sticky-table__th {% if request.sort_option.order == '-return_date' %}arrow-up {% elif request.sort_option.order == 'return_date' %}arrow-down {% else %}arrow-up-down {% endif %}" hx-get="{% url 'asset-history-search' %}?{{pd}}&sortby=return_date" hx-target="#historyTable">{% trans "Returned Date" %}</div>
<div class="oh-sticky-table__th">{% trans "Return Status" %}</div>
</div>
</div>
Expand All @@ -44,8 +44,8 @@
<div class="oh-sticky-table__td">
{{asset_assignement.assigned_to_employee_id}}
</div>
<div class="oh-sticky-table__td" data-cell-index="2">{{asset_assignement.assigned_date}} </div>
<div class="oh-sticky-table__td" data-cell-index="3">{{asset_assignement.return_date}}</div>
<div class="oh-sticky-table__td dateformat_changer" data-cell-index="2">{{asset_assignement.assigned_date}} </div>
<div class="oh-sticky-table__td dateformat_changer" data-cell-index="3">{{asset_assignement.return_date}}</div>
<div class="oh-sticky-table__td">{{asset_assignement.return_status}}</div>
</div>
{% endfor %}
Expand Down
7 changes: 7 additions & 0 deletions attendance/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
{
"menu": trans("Dashboard"),
"redirect": reverse("attendance-dashboard"),
"accessibility": "attendance.sidebar.dashboard_accessibility",
},
{
"menu": trans("Attendances"),
Expand Down Expand Up @@ -68,3 +69,9 @@ def work_record_accessibility(request, submenu, user_perms, *args, **kwargs):
return request.user.has_perm("attendance.view_attendance") or is_reportingmanager(
request.user
)


def dashboard_accessibility(request, submenu, user_perms, *args, **kwargs):
return request.user.has_perm("attendance.view_attendance") or is_reportingmanager(
request.user
)
8 changes: 6 additions & 2 deletions attendance/static/attendance/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1721,10 +1721,12 @@ $(".requested-attendance-row").change(function () {
// Iterate through all elements with the 'dateformat_changer' class and format their content

$(".dateformat_changer").each(function (index, element) {
var currentDate = $(element).text();
var currentDate = $(element).text().trim();
// Checking currentDate value is a date or None value.
if (/[\.,\-\/]/.test(currentDate)) {
var formattedDate = dateFormatter.getFormattedDate(currentDate);
} else if (currentDate) {
var formattedDate = currentDate;
} else {
var formattedDate = "None";
}
Expand All @@ -1741,11 +1743,13 @@ var formattedDate = dateFormatter.getFormattedDate(currentDate);

// Iterate through all elements with the 'timeformat_changer' class and format their content
$(".timeformat_changer").each(function (index, element) {
var currentTime = $(element).text();
var currentTime = $(element).text().trim();

// Checking currentTime value is a valid time.
if (/[\.:]/.test(currentTime)) {
var formattedTime = timeFormatter.getFormattedTime(currentTime);
} else if (currentTime) {
var formattedTime = currentTime;
} else {
var formattedTime = "None";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
>
{% trans "Overtime" %}
</div>
<div class="oh-sticky-table__th"></div>
<div class="oh-sticky-table__th">{% trans "Actions" %}</div>
</div>
</div>
{% for attendance in overtime_attendances %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}
{% load i18n static basefilters %}
<div
class="oh-card-dashboard oh-card-dashboard--no-scale oh-card-dashboard--transparent"
>
Expand Down Expand Up @@ -62,7 +62,7 @@
>
{% trans "Pending Hour" %}
</div>
<div class="oh-sticky-table__th oh-sticky-table__right"></div>
<div class="oh-sticky-table__th oh-sticky-table__right">{% trans "Actions" %}</div>
</div>
</div>
{% for attendance in validate_attendances %}
Expand Down Expand Up @@ -111,7 +111,7 @@
</div>
<div class="oh-sticky-table__td">{{attendance.hours_pending}}</div>
<div class="oh-sticky-table__td oh-sticky-table__right">
{% if perms.attendance.change_attendance %}
{% if perms.attendance.change_attendance or request.user|is_reportingmanager %}
<a
href='{% url "validate-this-attendance" attendance.id %}'
hx-target="#updateAttendanceBody"
Expand Down
17 changes: 17 additions & 0 deletions attendance/views/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,22 @@ def dashboard(request):
employee_id__is_active=True,
attendance_overtime_approve=False,
)
ot_attendances = filtersubordinates(
request=request,
perm="attendance.change_overtime",
queryset=ot_attendances,
)

validate_attendances = Attendance.objects.filter(
attendance_validated=False, employee_id__is_active=True
)

validate_attendances = filtersubordinates(
request=request,
perm="attendance.change_overtime",
queryset=validate_attendances,
)

return render(
request,
"attendance/dashboard/dashboard.html",
Expand Down Expand Up @@ -138,6 +149,12 @@ def validated_attendances_table(request):
validate_attendances = Attendance.objects.filter(
attendance_validated=False, employee_id__is_active=True
)
validate_attendances = filtersubordinates(
request=request,
perm="attendance.change_attendance",
queryset=validate_attendances,
)

context = {
"validate_attendances": paginator_qry(validate_attendances, page_number),
"pd": previous_data,
Expand Down
4 changes: 3 additions & 1 deletion base/horilla_company_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def all(self):
try:
model_name = queryset.model._meta.model_name
if model_name == "employee":
queryset = queryset.filter(is_active=True)
request = getattr(_thread_locals, "request", None)
if not getattr(request, "is_filtering", None):
queryset = queryset.filter(is_active=True)
else:
for field in queryset.model._meta.fields:
if isinstance(field, models.ForeignKey):
Expand Down
3 changes: 2 additions & 1 deletion base/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ def export_data(request, model, form_class, filter_class, file_name):
for format_name, format_string in date_formats.items():
if format_name == date_format:
value = start_date.strftime(format_string)

if isinstance(value, datetime):
value = str(value)
data_export[verbose_name].append(value)

data_frame = pd.DataFrame(data=data_export)
Expand Down
5 changes: 5 additions & 0 deletions base/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,4 +938,9 @@
views.activate_biometric_attendance,
name="activate-biometric-attendance",
),
path(
"emp-workinfo-complete",
views.employee_workinfo_complete,
name="emp-workinfo-complete",
),
]
145 changes: 107 additions & 38 deletions base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,101 @@ def home(request):
first_day_of_week = today - timedelta(days=today_weekday)
last_day_of_week = first_day_of_week + timedelta(days=6)

employees_with_pending = []
# employees_with_pending = []
employee_charts = DashboardEmployeeCharts.objects.get_or_create(
employee=request.user.employee_get
)[0]

# List of field names to focus on
# fields_to_focus = [
# "job_position_id",
# "department_id",
# "work_type_id",
# "employee_type_id",
# "job_role_id",
# "reporting_manager_id",
# "company_id",
# "location",
# "email",
# "mobile",
# "shift_id",
# "date_joining",
# "contract_end_date",
# "basic_salary",
# "salary_hour",
# ]

# for employee in EmployeeWorkInformation.objects.filter(employee_id__is_active=True):
# completed_field_count = sum(
# 1
# for field_name in fields_to_focus
# if getattr(employee, field_name) is not None
# )
# if completed_field_count < 14:
# # Create a dictionary with employee information and pending field count
# percent = f"{((completed_field_count / 14) * 100):.1f}"
# employee_info = {
# "employee": employee,
# "completed_field_count": percent,
# }
# employees_with_pending.append(employee_info)
# else:
# pass

# emps = Employee.objects.filter(employee_work_info__isnull=True)
# for emp in emps:
# employees_with_pending.insert(
# 0,
# {
# "employee": Workinfo(employee=emp),
# "completed_field_count": "0",
# },
# )
announcements = Announcement.objects.all()
general_expire = AnnouncementExpire.objects.all().first()
general_expire_date = 30 if not general_expire else general_expire.days

for announcement in announcements.filter(expire_date__isnull=True):
calculated_expire_date = announcement.created_at + timedelta(
days=general_expire_date
)
announcement.expire_date = calculated_expire_date
announcement.save()

# Check if the user has viewed the announcement
announcement_view = AnnouncementView.objects.filter(
announcement=announcement, user=request.user
).first()
announcement.has_viewed = (
announcement_view is not None and announcement_view.viewed
)

announcements = announcements.exclude(
expire_date__lt=datetime.today().date()
).order_by("-created_at")

announcement_list = announcements.filter(employees=request.user.employee_get)
announcement_list = announcement_list | announcements.filter(employees__isnull=True)
if request.user.has_perm("base.view_announcement"):
announcement_list = announcements

context = {
"first_day_of_week": first_day_of_week.strftime("%Y-%m-%d"),
"last_day_of_week": last_day_of_week.strftime("%Y-%m-%d"),
# "employees_with_pending": employees_with_pending,
"announcement": announcement_list,
"general_expire_date": general_expire_date,
"charts": employee_charts.charts,
}

return render(request, "index.html", context)


@login_required
def employee_workinfo_complete(request):

employees_with_pending = []

# List of field names to focus on
fields_to_focus = [
"job_position_id",
Expand All @@ -382,8 +472,13 @@ def home(request):
"basic_salary",
"salary_hour",
]

for employee in EmployeeWorkInformation.objects.filter(employee_id__is_active=True):
search = request.GET.get("search", "")
print("----------------")
print(search)
print("----------------")
for employee in EmployeeWorkInformation.objects.filter(
employee_id__employee_first_name__icontains=search, employee_id__is_active=True
):
completed_field_count = sum(
1
for field_name in fields_to_focus
Expand All @@ -409,44 +504,18 @@ def home(request):
"completed_field_count": "0",
},
)
announcements = Announcement.objects.all()
general_expire = AnnouncementExpire.objects.all().first()
general_expire_date = 30 if not general_expire else general_expire.days

for announcement in announcements.filter(expire_date__isnull=True):
calculated_expire_date = announcement.created_at + timedelta(
days=general_expire_date
)
announcement.expire_date = calculated_expire_date
announcement.save()

# Check if the user has viewed the announcement
announcement_view = AnnouncementView.objects.filter(
announcement=announcement, user=request.user
).first()
announcement.has_viewed = (
announcement_view is not None and announcement_view.viewed
)

announcements = announcements.exclude(
expire_date__lt=datetime.today().date()
).order_by("-created_at")
employees_with_pending.sort(key=lambda x: float(x["completed_field_count"]))

announcement_list = announcements.filter(employees=request.user.employee_get)
announcement_list = announcement_list | announcements.filter(employees__isnull=True)
if request.user.has_perm("base.view_announcement"):
announcement_list = announcements

context = {
"first_day_of_week": first_day_of_week.strftime("%Y-%m-%d"),
"last_day_of_week": last_day_of_week.strftime("%Y-%m-%d"),
"employees_with_pending": employees_with_pending,
"announcement": announcement_list,
"general_expire_date": general_expire_date,
"charts": employee_charts.charts,
}
employees_with_pending = paginator_qry(
employees_with_pending, request.GET.get("page")
)

return render(request, "index.html", context)
return render(
request,
"work_info_complete.html",
{"employees_with_pending": employees_with_pending},
)


@login_required
Expand Down
9 changes: 8 additions & 1 deletion horilla/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django_filters.filterset import FILTER_FOR_DBFIELD_DEFAULTS

from base.methods import reload_queryset
from base.thread_local_middleware import _thread_locals
from horilla_views.templatetags.generic_template_filters import getattribute

FILTER_FOR_DBFIELD_DEFAULTS[models.ForeignKey][
Expand Down Expand Up @@ -105,11 +106,17 @@ class HorillaFilterSet(FilterSet):
HorillaFilterSet
"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
request = getattr(_thread_locals, "request", None)
if request:
setattr(request, "is_filtering", True)

def search_in(self, queryset, name, value):
"""
Search in generic method for filter field
"""
search = value.lower()
search = self.data.get("search", "")
search_field = self.data.get("search_field")
if not search_field:
search_field = self.filters[name].field_name
Expand Down
Loading

0 comments on commit 137b5d9

Please sign in to comment.