Skip to content

Commit

Permalink
Merge pull request #1028 from frappe/version-14-hotfix
Browse files Browse the repository at this point in the history
chore: release v14
  • Loading branch information
ruchamahabal authored Nov 2, 2023
2 parents a124760 + d513af3 commit 5b74ea5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
22 changes: 17 additions & 5 deletions hrms/hr/doctype/shift_type/shift_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import frappe
from frappe.model.document import Document
from frappe.utils import cint, get_datetime, get_time, getdate
from frappe.utils import cint, create_batch, get_datetime, get_time, getdate

from erpnext.setup.doctype.employee.employee import get_holiday_list_for_employee
from erpnext.setup.doctype.holiday_list.holiday_list import is_holiday
Expand All @@ -21,6 +21,8 @@
from hrms.utils import get_date_range
from hrms.utils.holiday_list import get_holiday_dates_between

EMPLOYEE_CHUNK_SIZE = 50


class ShiftType(Document):
@frappe.whitelist()
Expand Down Expand Up @@ -63,8 +65,18 @@ def process_auto_attendance(self):
self.name,
)

for employee in self.get_assigned_employees(self.process_attendance_after, True):
self.mark_absent_for_dates_with_no_attendance(employee)
# commit after processing checkin logs to avoid losing progress
frappe.db.commit() # nosemgrep

assigned_employees = self.get_assigned_employees(self.process_attendance_after, True)

# mark absent in batches & commit to avoid losing progress since this tries to process remaining attendance
# right from "Process Attendance After" to "Last Sync of Checkin"
for batch in create_batch(assigned_employees, EMPLOYEE_CHUNK_SIZE):
for employee in batch:
self.mark_absent_for_dates_with_no_attendance(employee)

frappe.db.commit() # nosemgrep

def get_employee_checkins(self) -> list[dict]:
return frappe.get_all(
Expand Down Expand Up @@ -225,7 +237,7 @@ def get_marked_attendance_dates_between(
)
).run(pluck=True)

def get_assigned_employees(self, from_date=None, consider_default_shift=False):
def get_assigned_employees(self, from_date=None, consider_default_shift=False) -> list[str]:
filters = {"shift_type": self.name, "docstatus": "1", "status": "Active"}
if from_date:
filters["start_date"] = (">=", from_date)
Expand All @@ -239,7 +251,7 @@ def get_assigned_employees(self, from_date=None, consider_default_shift=False):
# exclude inactive employees
inactive_employees = frappe.db.get_all("Employee", {"status": "Inactive"}, pluck="name")

return set(assigned_employees) - set(inactive_employees)
return list(set(assigned_employees) - set(inactive_employees))

def get_employees_with_default_shift(self, filters: dict) -> list:
default_shift_employees = frappe.get_all(
Expand Down
4 changes: 3 additions & 1 deletion hrms/hr/doctype/shift_type/test_shift_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,9 @@ def test_skip_absent_marking_for_a_fallback_default_shift(self):

default_shift = setup_shift_type()
employee = make_employee(
"[email protected]", company="_Test Company", default_shift=default_shift.name
"[email protected]",
company="_Test Company",
default_shift=default_shift.name,
)

assigned_shift = setup_shift_type(shift_type="Test Absent with no Attendance")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@

from hrms.hr.doctype.attendance.attendance import mark_attendance
from hrms.hr.doctype.leave_application.test_leave_application import make_allocation_record
from hrms.hr.doctype.shift_type.test_shift_type import setup_shift_type
from hrms.hr.report.monthly_attendance_sheet.monthly_attendance_sheet import execute
from hrms.payroll.doctype.salary_slip.test_salary_slip import (
make_holiday_list,
make_leave_application,
)
from hrms.tests.test_utils import get_first_day_for_prev_month

test_dependencies = ["Shift Type"]


class TestMonthlyAttendanceSheet(FrappeTestCase):
def setUp(self):
self.company = "_Test Company"
self.employee = make_employee("[email protected]", company=self.company)
frappe.db.delete("Attendance")

if not frappe.db.exists("Shift Type", "Day Shift"):
setup_shift_type(shift_type="Day Shift")

date = getdate()
from_date = get_year_start(date)
to_date = get_year_ending(date)
Expand Down
16 changes: 13 additions & 3 deletions hrms/utils/holiday_list.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import frappe


def get_holiday_dates_between(holiday_list: str, start_date: str, end_date: str) -> list:
def get_holiday_dates_between(
holiday_list: str,
start_date: str,
end_date: str,
skip_weekly_offs: bool = False,
) -> list:
Holiday = frappe.qb.DocType("Holiday")
return (
query = (
frappe.qb.from_(Holiday)
.select(Holiday.holiday_date)
.where((Holiday.parent == holiday_list) & (Holiday.holiday_date.between(start_date, end_date)))
.orderby(Holiday.holiday_date)
).run(pluck=True)
)

if skip_weekly_offs:
query = query.where(Holiday.weekly_off == 0)

return query.run(pluck=True)

0 comments on commit 5b74ea5

Please sign in to comment.