From 96db78f7bc3295a3cf32214129f17195e2b3138f Mon Sep 17 00:00:00 2001 From: Anurag Mishra Date: Fri, 16 Jul 2021 12:45:09 +0530 Subject: [PATCH] fix: Test Cases --- erpnext/hr/doctype/attendance/attendance.py | 13 +++++++++++++ .../doctype/employee_checkin/employee_checkin.py | 9 ++++++++- erpnext/hr/doctype/shift_type/shift_type.py | 6 ++++++ .../doctype/overtime_slip/overtime_slip.py | 7 ++++++- .../doctype/overtime_slip/test_overtime_slip.py | 15 ++++++++++++--- .../doctype/overtime_type/test_overtime_type.py | 2 +- 6 files changed, 46 insertions(+), 6 deletions(-) diff --git a/erpnext/hr/doctype/attendance/attendance.py b/erpnext/hr/doctype/attendance/attendance.py index 7ffe96417a6..90716d09ef8 100644 --- a/erpnext/hr/doctype/attendance/attendance.py +++ b/erpnext/hr/doctype/attendance/attendance.py @@ -106,6 +106,15 @@ class Attendance(Document): def calculate_overtime_duration(self): #this method is only for Calculation of overtime based on Attendance through Employee Checkins self.overtime_duration = None + print("From calculate_overtime_duration") + print(self.working_time, self.standard_working_time, self.shift) + + if not self.standard_working_time and self.shift: + self.standard_working_time = frappe.db.get_value("Shift Type", self.shift, "standard_working_time") + + if not self.overtime_type: + self.overtime_type = get_overtime_type(self.employee) + if int(self.working_time) > int(self.standard_working_time): self.overtime_duration = int(self.working_time) - int(self.standard_working_time) @@ -156,6 +165,10 @@ def get_overtime_type(employee): if len(overtime_type_doc): overtime_type = overtime_type_doc[0].name + print("-------------->>> setting Overtime Type") + print(employee) + print(overtime_type) + return overtime_type @frappe.whitelist() diff --git a/erpnext/hr/doctype/employee_checkin/employee_checkin.py b/erpnext/hr/doctype/employee_checkin/employee_checkin.py index 58d166ffe66..24e00c7f159 100644 --- a/erpnext/hr/doctype/employee_checkin/employee_checkin.py +++ b/erpnext/hr/doctype/employee_checkin/employee_checkin.py @@ -111,6 +111,10 @@ def mark_attendance_and_link_log(logs, attendance_status, attendance_date, worki working_timedelta = timedelta(hours =int(working_time[1]), minutes = int(working_time[0] * 60)) from erpnext.hr.doctype.shift_type.shift_type import convert_time_into_duration working_time = convert_time_into_duration(working_timedelta) + + from pprint import pprint + print("------->>>>> mark_attendance_and_link_log") + doc_dict = { 'doctype': 'Attendance', 'employee': employee, @@ -124,9 +128,12 @@ def mark_attendance_and_link_log(logs, attendance_status, attendance_date, worki 'in_time': in_time, 'out_time': out_time } + pprint(doc_dict) attendance = frappe.get_doc(doc_dict).insert() - if frappe.db.get_value("Shift type", shift, "allow_overtime"): + print("--------------->>>>>>>>>> Allow Overtime") + print(frappe.db.get_value("Shift Type", shift, "allow_overtime")) + if frappe.db.get_value("Shift Type", shift, "allow_overtime"): attendance.calculate_overtime_duration() attendance.save() attendance.submit() diff --git a/erpnext/hr/doctype/shift_type/shift_type.py b/erpnext/hr/doctype/shift_type/shift_type.py index 39a1ef8a9da..5bfe0bb9936 100644 --- a/erpnext/hr/doctype/shift_type/shift_type.py +++ b/erpnext/hr/doctype/shift_type/shift_type.py @@ -59,8 +59,14 @@ class ShiftType(Document): else: checkins_log = itertools.groupby(logs, key=lambda x: (x['employee'], x['shift_actual_start'])) + print("------------>>>Checkins_log") + from pprint import pprint + for key, group in checkins_log: single_shift_logs = list(group) + + pprint(single_shift_logs) + attendance_status, working_hours, late_entry, early_exit, in_time, out_time = self.get_attendance(single_shift_logs) mark_attendance_and_link_log(single_shift_logs, attendance_status, key[1].date(), working_hours, late_entry, early_exit, in_time, out_time, self.name) diff --git a/erpnext/payroll/doctype/overtime_slip/overtime_slip.py b/erpnext/payroll/doctype/overtime_slip/overtime_slip.py index 6145112f954..6fe56776a71 100644 --- a/erpnext/payroll/doctype/overtime_slip/overtime_slip.py +++ b/erpnext/payroll/doctype/overtime_slip/overtime_slip.py @@ -54,6 +54,7 @@ class OvertimeSlip(Document): if overtime_based_on == "Attendance": records = self.get_attendance_record() if len(records): + print("Going to Create") self.create_overtime_details_row_for_attendance(records) elif overtime_based_on == "Timesheet": records = self.get_timesheet_record() @@ -80,6 +81,7 @@ class OvertimeSlip(Document): frappe.throw(_('Please Set "Standard Working Hours" in HR settings')) if record.overtime_duration: + print("Appending Row") self.append("overtime_details", { "reference_document_type": "Attendance", "reference_document": record.name, @@ -124,7 +126,10 @@ class OvertimeSlip(Document): AND ( overtime_duration IS NOT NULL OR overtime_duration != '00:00:00.000000' ) - """, (getdate(self.from_date), getdate(self.to_date), self.employee), as_dict=1) + """, (getdate(self.from_date), getdate(self.to_date), self.employee), as_dict=1, debug=1) + from pprint import pprint + print("----->>> Records") + pprint(records) return records return [] diff --git a/erpnext/payroll/doctype/overtime_slip/test_overtime_slip.py b/erpnext/payroll/doctype/overtime_slip/test_overtime_slip.py index 60974034e69..c675886a30d 100644 --- a/erpnext/payroll/doctype/overtime_slip/test_overtime_slip.py +++ b/erpnext/payroll/doctype/overtime_slip/test_overtime_slip.py @@ -46,6 +46,8 @@ class TestOvertimeSlip(unittest.TestCase): shift_type.last_sync_of_checkin = get_datetime(add_days(today(), 1)) shift_type.save() + print(shift_type.standard_working_time, shift_type.allow_overtime) + employee = make_employee("test_employee@overtime.com", company='_Test Company') make_salary_structure("structure for Overtime", "Monthly", employee=employee) @@ -54,13 +56,17 @@ class TestOvertimeSlip(unittest.TestCase): checkin = make_checkin(employee, time = get_datetime(today()) + timedelta(hours=9), log_type="IN") checkout = make_checkin(employee, time = get_datetime(today()) + timedelta(hours=20), log_type="OUT") + print("Checkins Asserted") + print(checkin.name) + print(checkout.name) self.assertEqual(checkin.shift, shift_type.name) self.assertEqual(checkout.shift, shift_type.name) - shift_type.reload() - - shift_type.process_auto_attendance() create_overtime_type(employee=employee) + shift_type.reload() + shift_type.process_auto_attendance() + print(employee) + checkin.reload() @@ -68,6 +74,9 @@ class TestOvertimeSlip(unittest.TestCase): 'shift': shift_type.name, 'status': 'Present' }, fields = ["name", "overtime_duration", "overtime_type", "attendance_date"]) + from pprint import pprint + pprint(attendance_records) + records = {} for record in attendance_records: records[record.name] = { diff --git a/erpnext/payroll/doctype/overtime_type/test_overtime_type.py b/erpnext/payroll/doctype/overtime_type/test_overtime_type.py index 9978cf5acfc..06e9fd60a9b 100644 --- a/erpnext/payroll/doctype/overtime_type/test_overtime_type.py +++ b/erpnext/payroll/doctype/overtime_type/test_overtime_type.py @@ -9,7 +9,7 @@ class TestOvertimeType(unittest.TestCase): def create_overtime_type(**args): args = frappe._dict(args) - + print(args.employee) overtime_type = frappe.new_doc("Overtime Type") overtime_type.name = "Test Overtime" overtime_type.applicable_for = args.applicable_for or "Employee"