[ADD] ATTENDANCE: Not validated hour feature
This commit is contained in:
@@ -462,6 +462,8 @@ class AttendanceFilters(FilterSet):
|
||||
"overtime_second__gte",
|
||||
"overtime_second",
|
||||
"department",
|
||||
"month",
|
||||
"year",
|
||||
]
|
||||
|
||||
widgets = {
|
||||
|
||||
@@ -71,6 +71,22 @@ def attendance_date_validate(date):
|
||||
raise ValidationError(_("You cannot choose a future date."))
|
||||
|
||||
|
||||
month_mapping = {
|
||||
"january": 1,
|
||||
"february": 2,
|
||||
"march": 3,
|
||||
"april": 4,
|
||||
"may": 5,
|
||||
"june": 6,
|
||||
"july": 7,
|
||||
"august": 8,
|
||||
"september": 9,
|
||||
"october": 10,
|
||||
"november": 11,
|
||||
"december": 12,
|
||||
}
|
||||
|
||||
|
||||
class AttendanceActivity(models.Model):
|
||||
"""
|
||||
AttendanceActivity model
|
||||
@@ -423,7 +439,10 @@ class Attendance(models.Model):
|
||||
"attendance_clock_in_date": "Attendance check-in date never smaller than attendance date"
|
||||
}
|
||||
)
|
||||
if self.attendance_clock_out_date and self.attendance_clock_out_date < self.attendance_clock_in_date:
|
||||
if (
|
||||
self.attendance_clock_out_date
|
||||
and self.attendance_clock_out_date < self.attendance_clock_in_date
|
||||
):
|
||||
raise ValidationError(
|
||||
{
|
||||
"attendance_clock_out_date": "Attendance check-out date never smaller than attendance check-in date"
|
||||
@@ -519,6 +538,45 @@ class AttendanceOverTime(models.Model):
|
||||
end_date = date(year, month + 1, 1) - timedelta(days=1)
|
||||
return start_date, end_date
|
||||
|
||||
def not_validated_hrs(self):
|
||||
"""
|
||||
This method will return not validated hours in a month
|
||||
"""
|
||||
hrs_to_vlaidate = sum(
|
||||
list(
|
||||
Attendance.objects.filter(
|
||||
attendance_date__month=month_mapping[self.month],
|
||||
attendance_date__year=self.year,
|
||||
employee_id=self.employee_id,
|
||||
attendance_validated=False,
|
||||
).values_list("at_work_second", flat=True)
|
||||
)
|
||||
)
|
||||
return format_time(hrs_to_vlaidate)
|
||||
|
||||
def not_approved_ot_hrs(self):
|
||||
"""
|
||||
This method will return the overtime hours to be approved
|
||||
"""
|
||||
hrs_to_approve = sum(
|
||||
list(
|
||||
Attendance.objects.filter(
|
||||
attendance_date__month=month_mapping[self.month],
|
||||
attendance_date__year=self.year,
|
||||
employee_id=self.employee_id,
|
||||
attendance_validated=True,
|
||||
attendance_overtime_approve=False,
|
||||
).values_list("overtime_second", flat=True)
|
||||
)
|
||||
)
|
||||
return format_time(hrs_to_approve)
|
||||
|
||||
def get_month_index(self):
|
||||
"""
|
||||
This method will return the index of the month
|
||||
"""
|
||||
return month_mapping[self.month]
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.hour_account_second = strtime_seconds(self.worked_hours)
|
||||
self.hour_pending_second = strtime_seconds(self.pending_hours)
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
<div class="oh-sticky-table__th" hx-get="{% url 'attendance-ot-search' %}?{{pd}}&sortby=month" hx-target="#ot-table">{% trans "Month" %}</div>
|
||||
<div class="oh-sticky-table__th" hx-get="{% url 'attendance-ot-search' %}?{{pd}}&sortby=year" hx-target="#ot-table">{% trans "Year" %}</div>
|
||||
<div class="oh-sticky-table__th" hx-get="{% url 'attendance-ot-search' %}?{{pd}}&sortby=hour_account_second" hx-target="#ot-table">{% trans "Worked Hours" %}</div>
|
||||
<div class="oh-sticky-table__th">{% trans "Hours to Validate" %}</div>
|
||||
<div class="oh-sticky-table__th">{% trans "Pending Hours" %}</div>
|
||||
<div class="oh-sticky-table__th" hx-get="{% url 'attendance-ot-search' %}?{{pd}}&sortby=overtime_second" hx-target="#ot-table">{% trans "Overtime Hours" %}</div>
|
||||
<div class="oh-sticky-table__th">{% trans "Not Approved OT Hours" %}</div>
|
||||
<div class="oh-sticky-table__th"></div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -53,8 +55,14 @@
|
||||
</div>
|
||||
<div class="oh-sticky-table__td">{{ot.year}}</div>
|
||||
<div class="oh-sticky-table__td">{{ot.worked_hours}}</div>
|
||||
<div class="oh-sticky-table__td" onclick="event.stopPropagation();localStorage.setItem('activeTabAttendance', '#tab_1');window.location.href=`{% url "attendance-view" %}?employee_id={{ot.employee_id.id}}&month={{ot.get_month_index}}&year={{ot.year}}`">
|
||||
{{ot.not_validated_hrs}}
|
||||
</div>
|
||||
<div class="oh-sticky-table__td">{{ot.pending_hours}}</div>
|
||||
<div class="oh-sticky-table__td">{{ot.overtime}}</div>
|
||||
<div class="oh-sticky-table__td" onclick="event.stopPropagation();localStorage.setItem('activeTabAttendance', '#tab_3');window.location.href=`{% url "attendance-view" %}?employee_id={{ot.employee_id.id}}&month={{ot.get_month_index}}&year={{ot.year}}`" >
|
||||
{{ot.not_approved_ot_hrs}}
|
||||
</div>
|
||||
<div class="oh-sticky-table__td" onclick="event.stopPropagation()">
|
||||
<div class="oh-btn-group">
|
||||
{% if perms.recruitment.change_attendanceovertime or request.user|is_reportingmanager %}
|
||||
|
||||
@@ -263,11 +263,15 @@ def attendance_view(request):
|
||||
overtime_second__gte=minot,
|
||||
attendance_validated=True,
|
||||
)
|
||||
filter_obj = AttendanceFilters(queryset=Attendance.objects.all())
|
||||
attendances = filtersubordinates(request, attendances, "attendance.view_attendance")
|
||||
filter_obj = AttendanceFilters(request.GET, queryset=attendances)
|
||||
attendances = filtersubordinates(
|
||||
request, filter_obj.qs, "attendance.view_attendance"
|
||||
)
|
||||
validate_attendances = AttendanceFilters(request.GET, queryset=validate_attendances).qs
|
||||
validate_attendances = filtersubordinates(
|
||||
request, validate_attendances, "attendance.view_attendance"
|
||||
)
|
||||
ot_attendances = AttendanceFilters(request.GET, queryset=ot_attendances).qs
|
||||
ot_attendances = filtersubordinates(
|
||||
request, ot_attendances, "attendance.view_attendance"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user