Skip to content

Commit 6f74942

Browse files
committed
fixed total working hour report
1 parent 0dedcfe commit 6f74942

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

ess/employee_self_service_portal/report/total_working_hours/total_working_hours.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import frappe
55
from frappe import _
6-
from frappe.utils import cint, get_datetime
6+
from frappe.utils import cint, get_datetime, flt
77

88
def execute(filters=None):
99
columns, data = [], []
@@ -35,13 +35,13 @@ def get_columns(filters=None):
3535
"width": 100
3636
},
3737
{
38-
"label": _("expected_Working Hours"),
38+
"label": _("Shift Length"),
3939
"fieldtype": "Float",
4040
"fieldname": "expected_working_hours",
4141
"width": 100
4242
},
4343
{
44-
"label": _("Working Hours"),
44+
"label": _("Worked Hours"),
4545
"fieldtype": "Float",
4646
"fieldname": "working_hours",
4747
"width": 100
@@ -113,27 +113,29 @@ def get_data(filters=None):
113113

114114
def update_shift_details(attendance_dict):
115115
shift_time_in_hours = 0.0
116+
# get shift start and end time
116117
shift_start_time = frappe.db.get_value("Shift Type",attendance_dict['shift'],'start_time')
117118
shift_end_time = frappe.db.get_value("Shift Type",attendance_dict['shift'],'end_time')
118-
if attendance_dict['check_in_date_time']:
119-
# attendance_dict['in_time'] = attendance_dict['check_in_date_time'].time()
120-
checkin_time = attendance_dict['check_in_date_time']
121-
else:
122-
checkin_time = frappe.utils.now_datetime()
123-
if attendance_dict['check_out_datetime']:
124-
# attendance_dict['out_time'] = attendance_dict['check_out_datetime'].time()
125-
checkout_time = attendance_dict['check_out_datetime']
126-
else:
127-
checkout_time = frappe.utils.now_datetime()
128-
attendance_dict['working_hours'] = time_diff_in_hours(checkin_time,checkout_time)
129-
119+
# calculate shift length if shift start and end time exists
130120
if shift_start_time and shift_end_time:
131121
shift_time_in_hours = time_diff_in_hours(shift_start_time,shift_end_time)
132122
attendance_dict['expected_working_hours'] = shift_time_in_hours
133-
attendance_dict['shift_time_in_hours'] = shift_time_in_hours
134-
if shift_time_in_hours > 0:
135-
work_hour_deviation =attendance_dict['working_hours']-shift_time_in_hours
136-
if work_hour_deviation >0:
137-
attendance_dict['overtime'] = work_hour_deviation
138-
else:
139-
attendance_dict['deficit'] = work_hour_deviation
123+
else:
124+
attendance_dict['expected_working_hours'] = 0.0
125+
# attendance_dict['shift_time_in_hours'] = shift_time_in_hours
126+
# get pun in and punch out time
127+
checkin_time = attendance_dict.get('check_in_date_time')
128+
checkout_time = attendance_dict.get('check_out_datetime')
129+
# if checkin out both exists calculate worked hours
130+
if checkin_time and checkout_time:
131+
attendance_dict['working_hours'] = time_diff_in_hours(checkin_time,checkout_time)
132+
else:
133+
attendance_dict['working_hours'] = 0.0
134+
135+
# get working hour deviation
136+
working_hour_deviation = flt(attendance_dict['expected_working_hours']- attendance_dict['working_hours'],2)
137+
# update overtime / deficit
138+
if working_hour_deviation >0:
139+
attendance_dict['overtime'] = working_hour_deviation
140+
else:
141+
attendance_dict['deficit'] = working_hour_deviation

0 commit comments

Comments
 (0)