Skip to content

Commit

Permalink
feat(Monthly Attendance Sheet): add Include Company Descendants filter
Browse files Browse the repository at this point in the history
  • Loading branch information
krantheman committed Sep 13, 2024
1 parent 12c28d0 commit 7beb013
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@ frappe.query_reports["Monthly Attendance Sheet"] = {
fieldtype: "Select",
options: ["", "Branch", "Grade", "Department", "Designation"],
},
{
fieldname: "include_company_descendants",
label: __("Include Company Descendants"),
fieldtype: "Check",
default: 1,
},
{
fieldname: "summarized_view",
label: __("Summarized View"),
fieldtype: "Check",
Default: 0,
default: 0,
},
],
onload: function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from frappe import _
from frappe.query_builder.functions import Count, Extract, Sum
from frappe.utils import cint, cstr, getdate
from frappe.utils.nestedset import get_descendants_of

Filters = frappe._dict

Expand All @@ -31,6 +32,11 @@ def execute(filters: Filters | None = None) -> tuple:
if not (filters.month and filters.year):
frappe.throw(_("Please select month and year."))

if filters.company:
filters.companies = [filters.company]
if filters.include_company_descendants:
filters.companies.extend(get_descendants_of("Company", filters.company))

attendance_map = get_attendance_map(filters)
if not attendance_map:
frappe.msgprint(_("No attendance records found."), alert=True, indicator="orange")
Expand Down Expand Up @@ -257,7 +263,7 @@ def get_attendance_records(filters: Filters) -> list[dict]:
)
.where(
(Attendance.docstatus == 1)
& (Attendance.company == filters.company)
& (Attendance.company.isin(filters.companies))
& (Extract("month", Attendance.attendance_date) == filters.month)
& (Extract("year", Attendance.attendance_date) == filters.year)
)
Expand Down Expand Up @@ -288,7 +294,7 @@ def get_employee_related_details(filters: Filters) -> tuple[dict, list]:
Employee.company,
Employee.holiday_list,
)
.where(Employee.company == filters.company)
.where(Employee.company.isin(filters.companies))
)

if filters.employee:
Expand Down Expand Up @@ -466,7 +472,7 @@ def get_attendance_summary_and_days(employee: str, filters: Filters) -> tuple[di
.where(
(Attendance.docstatus == 1)
& (Attendance.employee == employee)
& (Attendance.company == filters.company)
& (Attendance.company.isin(filters.companies))
& (Extract("month", Attendance.attendance_date) == filters.month)
& (Extract("year", Attendance.attendance_date) == filters.year)
)
Expand All @@ -479,7 +485,7 @@ def get_attendance_summary_and_days(employee: str, filters: Filters) -> tuple[di
.where(
(Attendance.docstatus == 1)
& (Attendance.employee == employee)
& (Attendance.company == filters.company)
& (Attendance.company.isin(filters.companies))
& (Extract("month", Attendance.attendance_date) == filters.month)
& (Extract("year", Attendance.attendance_date) == filters.year)
)
Expand Down Expand Up @@ -543,7 +549,7 @@ def get_leave_summary(employee: str, filters: Filters) -> dict[str, float]:
.where(
(Attendance.employee == employee)
& (Attendance.docstatus == 1)
& (Attendance.company == filters.company)
& (Attendance.company.isin(filters.companies))
& ((Attendance.leave_type.isnotnull()) | (Attendance.leave_type != ""))
& (Extract("month", Attendance.attendance_date) == filters.month)
& (Extract("year", Attendance.attendance_date) == filters.year)
Expand Down Expand Up @@ -577,7 +583,7 @@ def get_entry_exits_summary(employee: str, filters: Filters) -> dict[str, float]
.where(
(Attendance.docstatus == 1)
& (Attendance.employee == employee)
& (Attendance.company == filters.company)
& (Attendance.company.isin(filters.companies))
& (Extract("month", Attendance.attendance_date) == filters.month)
& (Extract("year", Attendance.attendance_date) == filters.year)
)
Expand Down

0 comments on commit 7beb013

Please sign in to comment.