Skip to content

Commit

Permalink
test: add test Employees Working on a Holiday report
Browse files Browse the repository at this point in the history
  • Loading branch information
krantheman committed Oct 18, 2024
1 parent 9f2200e commit 3e3ed07
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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("[email protected]", company=self.company, holiday_list=sunday_off)
emp2 = make_employee("[email protected]", company=self.company, holiday_list=monday_off)
emp3 = make_employee("[email protected]", 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])
11 changes: 8 additions & 3 deletions hrms/payroll/doctype/salary_slip/test_salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down

0 comments on commit 3e3ed07

Please sign in to comment.