[FIX] ATTENDANCE: Attendance 'Approve Overtime' button shows with condition and removed overtime field from update form
This commit is contained in:
@@ -119,7 +119,7 @@ class AttendanceUpdateForm(ModelForm):
|
||||
"requested_data",
|
||||
"is_validate_request",
|
||||
"is_validate_request_approved",
|
||||
"attendance_overtime_approve",
|
||||
"attendance_overtime",
|
||||
]
|
||||
model = Attendance
|
||||
widgets = {
|
||||
@@ -134,6 +134,8 @@ class AttendanceUpdateForm(ModelForm):
|
||||
if instance := kwargs.get("instance"):
|
||||
# django forms not showing value inside the date, time html element.
|
||||
# so here overriding default forms instance method to set initial value
|
||||
condition = AttendanceValidationCondition.objects.first()
|
||||
condition = strtime_seconds(condition.minimum_overtime_to_approve)
|
||||
initial = {
|
||||
"attendance_date": instance.attendance_date.strftime("%Y-%m-%d"),
|
||||
"attendance_clock_in": instance.attendance_clock_in.strftime("%H:%M"),
|
||||
@@ -151,6 +153,11 @@ class AttendanceUpdateForm(ModelForm):
|
||||
kwargs["initial"] = initial
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.fields['attendance_overtime_approve'].label = _("Approve overtime?")
|
||||
self.fields['attendance_validated'].label = _("Validate Attendance?")
|
||||
if strtime_seconds(instance.attendance_overtime) < condition or not instance.attendance_validated:
|
||||
del self.fields['attendance_overtime_approve']
|
||||
|
||||
def as_p(self, *args, **kwargs):
|
||||
"""
|
||||
Render the form fields as HTML table rows with Bootstrap styling.
|
||||
@@ -159,20 +166,6 @@ class AttendanceUpdateForm(ModelForm):
|
||||
table_html = render_to_string("attendance_form.html", context)
|
||||
return table_html
|
||||
|
||||
def clean(self) -> Dict[str, Any]:
|
||||
super().clean()
|
||||
overtime = strtime_seconds(self.cleaned_data["attendance_overtime"])
|
||||
minimum_hour = strtime_seconds(self.cleaned_data["minimum_hour"])
|
||||
at_work = strtime_seconds(self.cleaned_data["attendance_worked_hour"])
|
||||
if overtime > 0 and (at_work - minimum_hour) != overtime:
|
||||
raise ValidationError(
|
||||
{
|
||||
"attendance_overtime": "OT will calculate automatically, So set it to 00:00 or \
|
||||
manually add the OT"
|
||||
}
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
class AttendanceForm(ModelForm):
|
||||
"""
|
||||
|
||||
@@ -135,18 +135,18 @@ class Attendance(models.Model):
|
||||
null=True,
|
||||
verbose_name=_("Attendance day"),
|
||||
)
|
||||
attendance_clock_in = models.TimeField(
|
||||
null=True, verbose_name=_("Check-in"), help_text=_("First Check-in Time")
|
||||
)
|
||||
attendance_clock_in_date = models.DateField(
|
||||
null=True, verbose_name=_("Check-in date")
|
||||
)
|
||||
attendance_clock_out = models.TimeField(
|
||||
null=True, verbose_name=_("Check-out"), help_text=_("Last Check-out Time")
|
||||
attendance_clock_in = models.TimeField(
|
||||
null=True, verbose_name=_("Check-in"), help_text=_("First Check-in Time")
|
||||
)
|
||||
attendance_clock_out_date = models.DateField(
|
||||
null=True, verbose_name=_("Check-out date")
|
||||
)
|
||||
attendance_clock_out = models.TimeField(
|
||||
null=True, verbose_name=_("Check-out"), help_text=_("Last Check-out Time")
|
||||
)
|
||||
attendance_worked_hour = models.CharField(
|
||||
null=True,
|
||||
default="00:00",
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
var shiftId =selectElement.val()
|
||||
let parentForm = selectElement.parents().closest("form")
|
||||
var attendanceDate = parentForm.find("[name=attendance_date]").first().val()
|
||||
console.log(attendanceDate);
|
||||
console.log(shiftId);
|
||||
$.ajax({
|
||||
type: "post",
|
||||
url: "{% url 'update-shift-details' %}",
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
{% load attendancefilters %}
|
||||
{% load basefilters %}
|
||||
{% include 'filter_tags.html' %}
|
||||
<style>
|
||||
.disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="oh-tabs__content" id="tab_2">
|
||||
<!-- Sticky Table -->
|
||||
@@ -397,9 +403,15 @@
|
||||
{{attendance.attendance_overtime}}
|
||||
</div>
|
||||
<div class="oh-sticky-table__td">
|
||||
<a href="{% url 'approve-overtime' attendance.id %}" class="oh-btn oh-btn--info">
|
||||
{% if attendance.attendance_overtime_approve %}
|
||||
<a href="#" class="oh-btn oh-btn--info disabled">
|
||||
{% trans "Approve" %}
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="{% url 'approve-overtime' attendance.id %}" class="oh-btn oh-btn--info">
|
||||
{% trans "Approve" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="oh-sticky-table__td">
|
||||
<div class="oh-btn-group">
|
||||
|
||||
@@ -301,10 +301,8 @@
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
console.log('------------');
|
||||
const activeTab = localStorage.getItem('attendanceRequestActiveTab')
|
||||
if (activeTab!=null) {
|
||||
console.log(activeTab);
|
||||
$(".oh-tabs__content--active").toggleClass('oh-tabs__content--active');
|
||||
$(".oh-tabs__tab--active").toggleClass('oh-tabs__tab--active');
|
||||
$(`[data-target="${activeTab}"]`).toggleClass("oh-tabs__tab--active");
|
||||
|
||||
@@ -275,7 +275,6 @@ def attendance_view(request):
|
||||
validate_attendances = Attendance.objects.filter(attendance_validated=False)
|
||||
attendances = Attendance.objects.filter(attendance_validated=True)
|
||||
ot_attendances = Attendance.objects.filter(
|
||||
attendance_overtime_approve=False,
|
||||
overtime_second__gte=minot,
|
||||
attendance_validated=True,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user