Skip to content

Commit

Permalink
test: fix `test_consider_marked_attendance_on_holidays_with_unmarked_…
Browse files Browse the repository at this point in the history
…attendance` (frappe#1494)

- mark absent on holiday after DOJ only

- make sure unmarked attendance is not on a holiday
  • Loading branch information
ruchamahabal authored Mar 4, 2024
1 parent 565f123 commit bb22a85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 9 additions & 4 deletions hrms/payroll/doctype/salary_slip/test_salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,21 +533,26 @@ def test_consider_marked_attendance_on_holidays_with_unmarked_attendance(self):
joining_date = add_days(month_start_date, 3)

emp_id = make_employee(
"test_salary_slip_with_holidays_included@salary.com",
"test_salary_slip_with_holidays_included1@salary.com",
status="Active",
joining_date=joining_date,
date_of_joining=joining_date,
relieving_date=None,
)

for days in range(date_diff(month_end_date, add_days(joining_date, 1)) + 1):
for days in range(date_diff(month_end_date, joining_date) + 1):
date = add_days(joining_date, days)
if not is_holiday("Salary Slip Test Holiday List", date):
mark_attendance(emp_id, date, "Present", ignore_validate=True)

# mark absent on holiday
first_sunday = get_first_sunday(for_date=getdate())
first_sunday = get_first_sunday(for_date=joining_date, find_after_for_date=True)
mark_attendance(emp_id, first_sunday, "Absent", ignore_validate=True)

# unmarked attendance for a day
frappe.db.delete(
"Attendance", {"employee": emp_id, "attendance_date": add_days(first_sunday, 1)}
)

ss = make_employee_salary_slip(
emp_id,
"Monthly",
Expand Down
10 changes: 9 additions & 1 deletion hrms/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,17 @@ def set_defaults():
)


def get_first_sunday(holiday_list="Salary Slip Test Holiday List", for_date=None):
def get_first_sunday(
holiday_list="Salary Slip Test Holiday List", for_date=None, find_after_for_date=False
):
date = for_date or getdate()
month_start_date = get_first_day(date)

if find_after_for_date:
# explictly find first sunday after for_date
# useful when DOJ is after the month start
month_start_date = date

month_end_date = get_last_day(date)
first_sunday = frappe.db.sql(
"""
Expand Down

0 comments on commit bb22a85

Please sign in to comment.