|
3 | 3 |
|
4 | 4 | import frappe
|
5 | 5 | from frappe import _
|
6 |
| -from frappe.utils import cint, get_datetime |
| 6 | +from frappe.utils import cint, get_datetime, flt |
7 | 7 |
|
8 | 8 | def execute(filters=None):
|
9 | 9 | columns, data = [], []
|
@@ -35,13 +35,13 @@ def get_columns(filters=None):
|
35 | 35 | "width": 100
|
36 | 36 | },
|
37 | 37 | {
|
38 |
| - "label": _("expected_Working Hours"), |
| 38 | + "label": _("Shift Length"), |
39 | 39 | "fieldtype": "Float",
|
40 | 40 | "fieldname": "expected_working_hours",
|
41 | 41 | "width": 100
|
42 | 42 | },
|
43 | 43 | {
|
44 |
| - "label": _("Working Hours"), |
| 44 | + "label": _("Worked Hours"), |
45 | 45 | "fieldtype": "Float",
|
46 | 46 | "fieldname": "working_hours",
|
47 | 47 | "width": 100
|
@@ -113,27 +113,29 @@ def get_data(filters=None):
|
113 | 113 |
|
114 | 114 | def update_shift_details(attendance_dict):
|
115 | 115 | shift_time_in_hours = 0.0
|
| 116 | + # get shift start and end time |
116 | 117 | shift_start_time = frappe.db.get_value("Shift Type",attendance_dict['shift'],'start_time')
|
117 | 118 | 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 |
130 | 120 | if shift_start_time and shift_end_time:
|
131 | 121 | shift_time_in_hours = time_diff_in_hours(shift_start_time,shift_end_time)
|
132 | 122 | 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