diff --git a/hrms/hr/report/employees_working_on_a_holiday/test_employees_working_on_a_holiday.py b/hrms/hr/report/employees_working_on_a_holiday/test_employees_working_on_a_holiday.py new file mode 100644 index 0000000000..67ca4c25fe --- /dev/null +++ b/hrms/hr/report/employees_working_on_a_holiday/test_employees_working_on_a_holiday.py @@ -0,0 +1,69 @@ +from dateutil.relativedelta import relativedelta + +import frappe +from frappe.tests import IntegrationTestCase +from frappe.utils import add_days, get_year_ending, get_year_start, getdate + +from erpnext.setup.doctype.employee.test_employee import make_employee + +from hrms.hr.doctype.attendance.attendance import mark_attendance +from hrms.hr.report.employees_working_on_a_holiday.employees_working_on_a_holiday import execute +from hrms.payroll.doctype.salary_slip.test_salary_slip import make_holiday_list +from hrms.tests.test_utils import get_first_sunday + + +class TestEmployeesWorkingOnAHoliday(IntegrationTestCase): + def setUp(self): + self.company = "_Test Company" + frappe.db.delete("Attendance") + + def test_report(self): + date = getdate() + from_date = get_year_start(date) + to_date = get_year_ending(date) + sunday_off = make_holiday_list("Sunday Off", from_date, to_date, True) + monday_off = make_holiday_list("Monday Off", from_date, to_date, True, ["Monday"]) + tuesday_off = make_holiday_list("Tuesday Off", from_date, to_date, True, ["Tuesday"]) + + emp1 = make_employee("testemp@sunday.com", company=self.company, holiday_list=sunday_off) + emp2 = make_employee("testemp2@monday.com", company=self.company, holiday_list=monday_off) + emp3 = make_employee("testemp3@tuesday.com", company=self.company, holiday_list=tuesday_off) + + first_sunday = get_first_sunday() + # i realise this might not be the first monday and tuesday but doesn't matter for this test + first_monday = add_days(first_sunday, 1) + first_tuesday = add_days(first_monday, 1) + second_sunday = add_days(first_sunday, 7) + second_tuesday = add_days(first_tuesday, 7) + + # employees working on holidays + mark_attendance(emp1, first_sunday, "Present") + mark_attendance(emp1, second_sunday, "Present") + mark_attendance(emp2, first_monday, "Present") + mark_attendance(emp3, second_tuesday, "Present") + + # employees working on working days + mark_attendance(emp1, first_tuesday, "Present") + mark_attendance(emp2, first_sunday, "Present") + mark_attendance(emp3, first_monday, "Present") + + filters = frappe._dict( + { + "from_date": from_date, + "to_date": to_date, + "company": self.company, + } + ) + report = execute(filters=filters) + rows = report[1] + + self.assertEqual(len(rows), 4) + + weekly_offs = { + emp1: "Sunday", + emp2: "Monday", + emp3: "Tuesday", + } + + for d in rows: + self.assertEqual(weekly_offs[d[0]], d[4]) diff --git a/hrms/payroll/doctype/salary_slip/test_salary_slip.py b/hrms/payroll/doctype/salary_slip/test_salary_slip.py index 59fb23c8c8..886d05a56d 100644 --- a/hrms/payroll/doctype/salary_slip/test_salary_slip.py +++ b/hrms/payroll/doctype/salary_slip/test_salary_slip.py @@ -2219,7 +2219,9 @@ def make_payroll_period(): create_payroll_period(company=company, name=company_based_payroll_period[company]) -def make_holiday_list(list_name=None, from_date=None, to_date=None, add_weekly_offs=True): +def make_holiday_list( + list_name=None, from_date=None, to_date=None, add_weekly_offs=True, weekly_off_days=None +): fiscal_year = get_fiscal_year(nowdate(), company=erpnext.get_default_company()) name = list_name or "Salary Slip Test Holiday List" @@ -2235,8 +2237,11 @@ def make_holiday_list(list_name=None, from_date=None, to_date=None, add_weekly_o ).insert() if add_weekly_offs: - holiday_list.weekly_off = "Sunday" - holiday_list.get_weekly_off_dates() + if not weekly_off_days: + weekly_off_days = ["Sunday"] + for d in weekly_off_days: + holiday_list.weekly_off = d + holiday_list.get_weekly_off_dates() holiday_list.save() holiday_list = holiday_list.name