fix: Test Cases

This commit is contained in:
Anurag Mishra
2021-07-16 12:45:09 +05:30
parent 32f3b24c3a
commit 96db78f7bc
6 changed files with 46 additions and 6 deletions

View File

@@ -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()

View File

@@ -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()

View File

@@ -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)

View File

@@ -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 []

View File

@@ -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] = {

View File

@@ -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"