diff --git a/erpnext/hr/doctype/attendance/test_attendance.py b/erpnext/hr/doctype/attendance/test_attendance.py index 677a84100d0..b78f5c06206 100644 --- a/erpnext/hr/doctype/attendance/test_attendance.py +++ b/erpnext/hr/doctype/attendance/test_attendance.py @@ -19,7 +19,7 @@ from erpnext.hr.doctype.attendance.attendance import ( mark_attendance, ) from erpnext.hr.doctype.employee.test_employee import make_employee -from erpnext.hr.doctype.leave_application.test_leave_application import get_first_sunday +from erpnext.hr.tests.test_utils import get_first_sunday test_records = frappe.get_test_records("Attendance") diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py index 9f263e2a17e..f36d0f2da86 100644 --- a/erpnext/hr/doctype/leave_application/test_leave_application.py +++ b/erpnext/hr/doctype/leave_application/test_leave_application.py @@ -33,6 +33,7 @@ from erpnext.hr.doctype.leave_policy_assignment.leave_policy_assignment import ( create_assignment_for_multiple_employees, ) from erpnext.hr.doctype.leave_type.test_leave_type import create_leave_type +from erpnext.hr.tests.test_utils import get_first_sunday from erpnext.payroll.doctype.salary_slip.test_salary_slip import ( make_holiday_list, make_leave_application, @@ -1105,23 +1106,6 @@ def allocate_leaves(employee, leave_period, leave_type, new_leaves_allocated, el allocate_leave.submit() -def get_first_sunday(holiday_list="Salary Slip Test Holiday List", for_date=None): - date = for_date or getdate() - month_start_date = get_first_day(date) - month_end_date = get_last_day(date) - first_sunday = frappe.db.sql( - """ - select holiday_date from `tabHoliday` - where parent = %s - and holiday_date between %s and %s - order by holiday_date - """, - (holiday_list, month_start_date, month_end_date), - )[0][0] - - return first_sunday - - def make_policy_assignment(employee, leave_type, leave_period): frappe.delete_doc_if_exists("Leave Type", leave_type, force=1) frappe.get_doc( diff --git a/erpnext/hr/report/employee_leave_balance/test_employee_leave_balance.py b/erpnext/hr/report/employee_leave_balance/test_employee_leave_balance.py index 5354abf4f6f..d167d1d86c9 100644 --- a/erpnext/hr/report/employee_leave_balance/test_employee_leave_balance.py +++ b/erpnext/hr/report/employee_leave_balance/test_employee_leave_balance.py @@ -9,13 +9,11 @@ from frappe.utils import add_days, add_months, flt, get_year_ending, get_year_st from erpnext.hr.doctype.employee.test_employee import make_employee from erpnext.hr.doctype.holiday_list.test_holiday_list import set_holiday_list -from erpnext.hr.doctype.leave_application.test_leave_application import ( - get_first_sunday, - make_allocation_record, -) +from erpnext.hr.doctype.leave_application.test_leave_application import make_allocation_record from erpnext.hr.doctype.leave_ledger_entry.leave_ledger_entry import process_expired_allocation from erpnext.hr.doctype.leave_type.test_leave_type import create_leave_type from erpnext.hr.report.employee_leave_balance.employee_leave_balance import execute +from erpnext.hr.tests.test_utils import get_first_sunday from erpnext.payroll.doctype.salary_slip.test_salary_slip import ( make_holiday_list, make_leave_application, diff --git a/erpnext/hr/report/employee_leave_balance_summary/test_employee_leave_balance_summary.py b/erpnext/hr/report/employee_leave_balance_summary/test_employee_leave_balance_summary.py index 2fd74b7983b..9eddbea02e2 100644 --- a/erpnext/hr/report/employee_leave_balance_summary/test_employee_leave_balance_summary.py +++ b/erpnext/hr/report/employee_leave_balance_summary/test_employee_leave_balance_summary.py @@ -9,12 +9,10 @@ from frappe.utils import add_days, flt, get_year_ending, get_year_start, getdate from erpnext.hr.doctype.employee.test_employee import make_employee from erpnext.hr.doctype.holiday_list.test_holiday_list import set_holiday_list -from erpnext.hr.doctype.leave_application.test_leave_application import ( - get_first_sunday, - make_allocation_record, -) +from erpnext.hr.doctype.leave_application.test_leave_application import make_allocation_record from erpnext.hr.doctype.leave_ledger_entry.leave_ledger_entry import process_expired_allocation from erpnext.hr.report.employee_leave_balance_summary.employee_leave_balance_summary import execute +from erpnext.hr.tests.test_utils import get_first_sunday from erpnext.payroll.doctype.salary_slip.test_salary_slip import ( make_holiday_list, make_leave_application, diff --git a/erpnext/hr/tests/test_utils.py b/erpnext/hr/tests/test_utils.py new file mode 100644 index 00000000000..3d7c1ad3669 --- /dev/null +++ b/erpnext/hr/tests/test_utils.py @@ -0,0 +1,19 @@ +import frappe +from frappe.utils import get_first_day, get_last_day, getdate + + +def get_first_sunday(holiday_list="Salary Slip Test Holiday List", for_date=None): + date = for_date or getdate() + month_start_date = get_first_day(date) + month_end_date = get_last_day(date) + first_sunday = frappe.db.sql( + """ + select holiday_date from `tabHoliday` + where parent = %s + and holiday_date between %s and %s + order by holiday_date + """, + (holiday_list, month_start_date, month_end_date), + )[0][0] + + return first_sunday diff --git a/erpnext/payroll/doctype/employee_benefit_application/test_employee_benefit_application.py b/erpnext/payroll/doctype/employee_benefit_application/test_employee_benefit_application.py index de8f9b6a7ad..f2b86b3ff37 100644 --- a/erpnext/payroll/doctype/employee_benefit_application/test_employee_benefit_application.py +++ b/erpnext/payroll/doctype/employee_benefit_application/test_employee_benefit_application.py @@ -9,7 +9,7 @@ from frappe.utils import add_days, date_diff, get_year_ending, get_year_start, g from erpnext.hr.doctype.employee.test_employee import make_employee from erpnext.hr.doctype.holiday_list.test_holiday_list import set_holiday_list -from erpnext.hr.doctype.leave_application.test_leave_application import get_first_sunday +from erpnext.hr.tests.test_utils import get_first_sunday from erpnext.hr.utils import get_holiday_dates_for_employee from erpnext.payroll.doctype.employee_benefit_application.employee_benefit_application import ( calculate_lwp, diff --git a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py index 555d2da409f..6e3b57239d4 100644 --- a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py @@ -27,6 +27,7 @@ from erpnext.hr.doctype.attendance.attendance import mark_attendance from erpnext.hr.doctype.employee.test_employee import make_employee from erpnext.hr.doctype.leave_allocation.test_leave_allocation import create_leave_allocation from erpnext.hr.doctype.leave_type.test_leave_type import create_leave_type +from erpnext.hr.tests.test_utils import get_first_sunday from erpnext.payroll.doctype.employee_tax_exemption_declaration.test_employee_tax_exemption_declaration import ( create_exemption_category, create_payroll_period, @@ -55,18 +56,7 @@ class TestSalarySlip(FrappeTestCase): frappe.db.set_value("Leave Type", "Leave Without Pay", "include_holiday", 0) - month_start_date = get_first_day(nowdate()) - month_end_date = get_last_day(nowdate()) - - first_sunday = frappe.db.sql( - """ - select holiday_date from `tabHoliday` - where parent = 'Salary Slip Test Holiday List' - and holiday_date between %s and %s - order by holiday_date - """, - (month_start_date, month_end_date), - )[0][0] + first_sunday = get_first_sunday() mark_attendance(emp_id, first_sunday, "Absent", ignore_validate=True) # invalid lwp mark_attendance( @@ -273,19 +263,7 @@ class TestSalarySlip(FrappeTestCase): frappe.db.set_value("Leave Type", "Leave Without Pay", "include_holiday", 0) - month_start_date = get_first_day(nowdate()) - month_end_date = get_last_day(nowdate()) - - first_sunday = frappe.db.sql( - """ - select holiday_date from `tabHoliday` - where parent = 'Salary Slip Test Holiday List' - and holiday_date between %s and %s - order by holiday_date - """, - (month_start_date, month_end_date), - )[0][0] - + first_sunday = get_first_sunday() make_leave_application(emp_id, first_sunday, add_days(first_sunday, 3), "Leave Without Pay") leave_type_ppl = create_leave_type(leave_type_name="Test Partially Paid Leave", is_ppl=1) @@ -338,19 +316,7 @@ class TestSalarySlip(FrappeTestCase): frappe.db.set_value("Employee", emp, {"relieving_date": None, "status": "Active"}) # mark attendance - month_start_date = get_first_day(nowdate()) - month_end_date = get_last_day(nowdate()) - - first_sunday = frappe.db.sql( - """ - select holiday_date from `tabHoliday` - where parent = 'Salary Slip Test Holiday List' - and holiday_date between %s and %s - order by holiday_date - """, - (month_start_date, month_end_date), - )[0][0] - + first_sunday = get_first_sunday() mark_attendance( emp, add_days(first_sunday, 1), "Absent", ignore_validate=True ) # counted as absent @@ -359,8 +325,8 @@ class TestSalarySlip(FrappeTestCase): make_salary_structure_for_timesheet(emp) timesheet = make_timesheet(emp, simulate=True, is_billable=1) salary_slip = make_salary_slip_for_timesheet(timesheet.name) - salary_slip.start_date = month_start_date - salary_slip.end_date = month_end_date + salary_slip.start_date = get_first_day(nowdate()) + salary_slip.end_date = get_last_day(nowdate()) salary_slip.save() salary_slip.submit() salary_slip.reload() @@ -402,18 +368,7 @@ class TestSalarySlip(FrappeTestCase): ) # mark employee absent for a day since this case works fine if payment days are equal to working days - month_start_date = get_first_day(nowdate()) - month_end_date = get_last_day(nowdate()) - - first_sunday = frappe.db.sql( - """ - select holiday_date from `tabHoliday` - where parent = 'Salary Slip Test Holiday List' - and holiday_date between %s and %s - order by holiday_date - """, - (month_start_date, month_end_date), - )[0][0] + first_sunday = get_first_sunday() mark_attendance( employee, add_days(first_sunday, 1), "Absent", ignore_validate=True @@ -1041,7 +996,6 @@ class TestSalarySlip(FrappeTestCase): Tests whether component using statistical component in the formula gets the updated value based on payment days """ - from erpnext.hr.doctype.leave_application.test_leave_application import get_first_sunday from erpnext.payroll.doctype.salary_structure.test_salary_structure import ( create_salary_structure_assignment, )