[UPDT] ATTENDANCE: Attendace request method
This commit is contained in:
@@ -73,16 +73,19 @@ def get_diff_dict(first_dict, other_dict, model=None):
|
||||
"%d %b %Y"
|
||||
)
|
||||
elif isinstance(field, models.TimeField):
|
||||
if value is not None and value != 'None':
|
||||
if value is not None and value != "None":
|
||||
if len(value.split(":")) == 2:
|
||||
value = value + ":00"
|
||||
value = datetime.strptime(value, "%H:%M:%S").strftime("%I:%M %p")
|
||||
if other_value is not None and value != 'None':
|
||||
if other_value is not None and value != "None":
|
||||
if len(other_value.split(":")) == 2:
|
||||
other_value = other_value + ":00"
|
||||
other_value = datetime.strptime(other_value, "%H:%M:%S").strftime(
|
||||
"%I:%M %p"
|
||||
)
|
||||
if other_value != "None":
|
||||
other_value = datetime.strptime(
|
||||
other_value, "%H:%M:%S"
|
||||
).strftime("%I:%M %p")
|
||||
else:
|
||||
other_value = "None"
|
||||
elif isinstance(field, models.ForeignKey):
|
||||
if value is not None and len(str(value)):
|
||||
value = field.related_model.objects.get(id=value)
|
||||
|
||||
@@ -301,21 +301,21 @@ class Attendance(models.Model):
|
||||
end_date = holi.end_date
|
||||
|
||||
# Convert start_date and end_date to datetime objects
|
||||
start_date = datetime.strptime(str(start_date), '%Y-%m-%d')
|
||||
end_date = datetime.strptime(str(end_date), '%Y-%m-%d')
|
||||
start_date = datetime.strptime(str(start_date), "%Y-%m-%d")
|
||||
end_date = datetime.strptime(str(end_date), "%Y-%m-%d")
|
||||
|
||||
# Add dates in between start date and end date including both
|
||||
current_date = start_date
|
||||
while current_date <= end_date:
|
||||
leaves.append(current_date.strftime('%Y-%m-%d'))
|
||||
leaves.append(current_date.strftime("%Y-%m-%d"))
|
||||
current_date += timedelta(days=1)
|
||||
|
||||
|
||||
# Checking attendance date is in holiday list, if found making the minimum hour to 00:00
|
||||
for leave in leaves:
|
||||
if str(leave) == str(self.attendance_date):
|
||||
self.minimum_hour = '00:00'
|
||||
self.minimum_hour = "00:00"
|
||||
break
|
||||
|
||||
|
||||
# Making a dictonary contains week day value and leave day pairs
|
||||
company_leaves = {}
|
||||
company_leave = CompanyLeave.objects.all()
|
||||
@@ -325,19 +325,19 @@ class Attendance(models.Model):
|
||||
company_leaves[b] = a
|
||||
|
||||
# Checking the attendance date is in which week
|
||||
week_in_month = str(((self.attendance_date.day - 1) // 7 + 1)-1)
|
||||
week_in_month = str(((self.attendance_date.day - 1) // 7 + 1) - 1)
|
||||
|
||||
# Checking the attendance date is in the company leave or not
|
||||
for pairs in company_leaves.items():
|
||||
# For all weeks based_on_week is None
|
||||
if str(pairs[0]) == 'None':
|
||||
if str(pairs[0]) == "None":
|
||||
if str(pairs[1]) == str(self.attendance_day):
|
||||
self.minimum_hour = '00:00'
|
||||
self.minimum_hour = "00:00"
|
||||
break
|
||||
# Checking with based_on_week and attendance_date week
|
||||
if str(pairs[0]) == week_in_month:
|
||||
if str(pairs[1]) == str(self.attendance_day):
|
||||
self.minimum_hour = '00:00'
|
||||
self.minimum_hour = "00:00"
|
||||
break
|
||||
|
||||
condition = AttendanceValidationCondition.objects.first()
|
||||
|
||||
@@ -9,6 +9,7 @@ from urllib.parse import parse_qs
|
||||
from django.shortcuts import render
|
||||
from django.contrib import messages
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from notifications.signals import notify
|
||||
from horilla.decorators import login_required, manager_can_enter
|
||||
from base.methods import (
|
||||
@@ -18,7 +19,7 @@ from base.methods import (
|
||||
get_key_instances,
|
||||
)
|
||||
from employee.models import Employee
|
||||
from attendance.models import Attendance
|
||||
from attendance.models import Attendance, AttendanceActivity
|
||||
from attendance.forms import AttendanceRequestForm, NewRequestForm
|
||||
from attendance.methods.differentiate import get_diff_dict
|
||||
from attendance.views.views import paginator_qry
|
||||
@@ -129,7 +130,7 @@ def request_new(request):
|
||||
if form.is_valid():
|
||||
if form.new_instance is not None:
|
||||
form.new_instance.save()
|
||||
messages.success(request, "New attendance request created")
|
||||
messages.success(request, _("New attendance request created"))
|
||||
return HttpResponse(
|
||||
render(
|
||||
request,
|
||||
@@ -138,7 +139,7 @@ def request_new(request):
|
||||
).content.decode("utf-8")
|
||||
+ "<script>location.reload();</script>"
|
||||
)
|
||||
messages.success(request, "Update request updated")
|
||||
messages.success(request, _("Update request updated"))
|
||||
return HttpResponse(
|
||||
render(
|
||||
request,
|
||||
@@ -205,7 +206,7 @@ def attendance_request_changes(request, attendance_id):
|
||||
instance.is_validate_request_approved = False
|
||||
instance.is_validate_request = True
|
||||
instance.save()
|
||||
messages.success(request, "Attendance update request created.")
|
||||
messages.success(request, _("Attendance update request created."))
|
||||
employee = attendance.employee_id
|
||||
if attendance.employee_id.employee_work_info.reporting_manager_id:
|
||||
reporting_manager = (
|
||||
@@ -289,6 +290,9 @@ def approve_validate_attendance_request(request, attendance_id):
|
||||
This method is used to validate the attendance requests
|
||||
"""
|
||||
attendance = Attendance.objects.get(id=attendance_id)
|
||||
prev_attendance_date = attendance.attendance_date
|
||||
prev_attendance_clock_in_date = attendance.attendance_clock_in_date
|
||||
prev_attendance_clock_in = attendance.attendance_clock_in
|
||||
attendance.attendance_validated = True
|
||||
attendance.is_validate_request_approved = True
|
||||
attendance.is_validate_request = False
|
||||
@@ -310,7 +314,33 @@ def approve_validate_attendance_request(request, attendance_id):
|
||||
# DUE TO AFFECT THE OVERTIME CALCULATION ON SAVE METHOD, SAVE THE INSTANCE ONCE MORE
|
||||
attendance = Attendance.objects.get(id=attendance_id)
|
||||
attendance.save()
|
||||
messages.success(request, "Attendance request has been approved")
|
||||
if (
|
||||
attendance.attendance_clock_out is None
|
||||
or attendance.attendance_clock_out_date is None
|
||||
):
|
||||
attendance.attendance_validated = True
|
||||
activity = AttendanceActivity.objects.filter(
|
||||
employee_id=attendance.employee_id,
|
||||
attendance_date=prev_attendance_date,
|
||||
clock_in_date=prev_attendance_clock_in_date,
|
||||
clock_in=prev_attendance_clock_in,
|
||||
)
|
||||
if activity:
|
||||
activity.update(
|
||||
employee_id=attendance.employee_id,
|
||||
attendance_date=attendance.attendance_date,
|
||||
clock_in_date=attendance.attendance_clock_in_date,
|
||||
clock_in=attendance.attendance_clock_in,
|
||||
)
|
||||
|
||||
else:
|
||||
AttendanceActivity.objects.create(
|
||||
employee_id=attendance.employee_id,
|
||||
attendance_date=attendance.attendance_date,
|
||||
clock_in_date=attendance.attendance_clock_in_date,
|
||||
clock_in=attendance.attendance_clock_in,
|
||||
)
|
||||
messages.success(request, _("Attendance request has been approved"))
|
||||
employee = attendance.employee_id
|
||||
notify.send(
|
||||
request.user,
|
||||
@@ -372,9 +402,9 @@ def cancel_attendance_request(request, attendance_id):
|
||||
attendance.save()
|
||||
if attendance.request_type == "create_request":
|
||||
attendance.delete()
|
||||
messages.success(request, "The requested attendance is removed.")
|
||||
messages.success(request, _("The requested attendance is removed."))
|
||||
else:
|
||||
messages.success(request, "Attendance request has been cancelled")
|
||||
messages.success(request, _("Attendance request has been cancelled"))
|
||||
employee = attendance.employee_id
|
||||
notify.send(
|
||||
request.user,
|
||||
|
||||
Reference in New Issue
Block a user