Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions hrms/api/roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,27 +273,26 @@ def get_leaves(month_start: str, month_end: str, employee_filters: dict[str, str
LeaveApplication = frappe.qb.DocType("Leave Application")
Employee = frappe.qb.DocType("Employee")

frappe.has_permission("Leave Application", "read", throw=True)

query = (
frappe.qb.select(
query = frappe.qb.get_query(
"Leave Application",
fields=[
LeaveApplication.name.as_("leave"),
LeaveApplication.employee,
LeaveApplication.leave_type,
LeaveApplication.from_date,
LeaveApplication.to_date,
)
.from_(LeaveApplication)
.left_join(Employee)
.on(LeaveApplication.employee == Employee.name)
.where(
(LeaveApplication.docstatus == 1)
& (LeaveApplication.status == "Approved")
& (LeaveApplication.from_date <= month_end)
& (LeaveApplication.to_date >= month_start)
)
],
filters={
"docstatus": 1,
"status": "Approved",
"from_date": ("<=", month_end),
"to_date": (">=", month_start),
},
ignore_permissions=False,
)

query = query.left_join(Employee).on(LeaveApplication.employee == Employee.name)

for filter in employee_filters:
query = query.where(Employee[filter] == employee_filters[filter])

Expand All @@ -309,8 +308,9 @@ def get_shifts(
ShiftType = frappe.qb.DocType("Shift Type")
Employee = frappe.qb.DocType("Employee")

query = (
frappe.qb.select(
query = frappe.qb.get_query(
"Shift Assignment",
fields=[
ShiftAssignment.name,
ShiftAssignment.employee,
ShiftAssignment.shift_type,
Expand All @@ -322,17 +322,23 @@ def get_shifts(
ShiftType.start_time,
ShiftType.end_time,
ShiftType.color,
)
.from_(ShiftAssignment)
.left_join(ShiftType)
],
filters={
"docstatus": 1,
"start_date": ("<=", month_end),
},
ignore_permissions=False,
)

# end_date is open-ended (None for shifts with no defined end) — must be
# expressed as an OR, which the filters dict can't represent cleanly.
query = query.where((ShiftAssignment.end_date >= month_start) | (ShiftAssignment.end_date.isnull()))

query = (
query.left_join(ShiftType)
.on(ShiftAssignment.shift_type == ShiftType.name)
.left_join(Employee)
.on(ShiftAssignment.employee == Employee.name)
.where(
(ShiftAssignment.docstatus == 1)
& (ShiftAssignment.start_date <= month_end)
& ((ShiftAssignment.end_date >= month_start) | (ShiftAssignment.end_date.isnull()))
)
)

for filter in employee_filters:
Expand Down
64 changes: 33 additions & 31 deletions hrms/hr/doctype/goal/goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,48 +163,50 @@ def update_goal_progress_in_appraisal(self):

@frappe.whitelist()
def get_children(doctype: str, parent: str, is_root: bool = False, **filters) -> list[dict]:
Goal = frappe.qb.DocType(doctype)

query = (
frappe.qb.from_(Goal)
.select(
Goal.name.as_("value"),
Goal.goal_name.as_("title"),
Goal.is_group.as_("expandable"),
Goal.status,
Goal.employee,
Goal.employee_name,
Goal.appraisal_cycle,
Goal.progress,
Goal.kra,
)
.where(Goal.status != "Archived")
)
query_filters = [["status", "!=", "Archived"]]
query_or_filters = []

if filters.get("employee"):
query = query.where(Goal.employee == filters.get("employee"))
query_filters.append(["employee", "=", filters.get("employee")])

if filters.get("appraisal_cycle"):
query = query.where(Goal.appraisal_cycle == filters.get("appraisal_cycle"))
query_filters.append(["appraisal_cycle", "=", filters.get("appraisal_cycle")])

if filters.get("goal"):
query = query.where(Goal.parent_goal == filters.get("goal"))
query_filters.append(["parent_goal", "=", filters.get("goal")])

elif parent and not is_root:
# via expand child
query = query.where(Goal.parent_goal == parent)
query_filters.append(["parent_goal", "=", parent])

else:
ifnull = CustomFunction("IFNULL", ["value", "default"])
query = query.where(ifnull(Goal.parent_goal, "") == "")
query_filters.append(["parent_goal", "in", ["", None]])

if filters.get("date_range"):
date_range = frappe.parse_json(filters.get("date_range"))

query = query.where(
(Goal.start_date.between(date_range[0], date_range[1]))
& ((Goal.end_date.isnull()) | (Goal.end_date.between(date_range[0], date_range[1])))
)
from_date, to_date = frappe.parse_json(filters.get("date_range"))
query_filters.append(["start_date", "between", [from_date, to_date]])

# or_filters
query_or_filters.append(["end_date", "is", "not set"])
query_or_filters.append(["end_date", "between", [from_date, to_date]])

goals = frappe.get_list(
doctype,
fields=[
"name as value",
"goal_name as title",
"is_group as expandable",
"status",
"employee",
"employee_name",
"appraisal_cycle",
"progress",
"kra",
],
filters=query_filters,
or_filters=query_or_filters if query_or_filters else None,
order_by="employee, kra",
)

goals = query.orderby(Goal.employee, Goal.kra).run(as_dict=True)
_update_goal_completion_status(goals)

return goals
Expand Down
8 changes: 4 additions & 4 deletions hrms/locale/fa.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ msgstr ""
"Project-Id-Version: frappe\n"
"Report-Msgid-Bugs-To: contact@frappe.io\n"
"POT-Creation-Date: 2026-05-31 10:16+0000\n"
"PO-Revision-Date: 2026-06-01 14:00\n"
"PO-Revision-Date: 2026-06-07 15:12\n"
"Last-Translator: contact@frappe.io\n"
"Language-Team: Persian\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -297,7 +297,7 @@ msgstr "<table class='table table-bordered'><tr><th>{0}</th><th>{1}</th></tr>"

#: hrms/hr/doctype/job_requisition/job_requisition.js:101
msgid "A Job Requisition already exists for {0} requested by {1} for the same department.<br> Do you want to continue?"
msgstr ""
msgstr "یک درخواست شغل برای {0} که توسط {1} برای همان بخش درخواست شده است، از قبل وجود دارد.<br> آیا می‌خواهید ادامه دهید؟"

#: hrms/controllers/employee_reminders.py:123
#: hrms/controllers/employee_reminders.py:216
Expand Down Expand Up @@ -5439,15 +5439,15 @@ msgstr "زمان‌های شیفت نامعتبر است"

#: hrms/api/roster.py:31
msgid "Invalid employee filter: {0}"
msgstr ""
msgstr "فیلتر کارمند نامعتبر: {0}"

#: hrms/hr/doctype/expense_claim/expense_claim.py:879
msgid "Invalid parameters provided. Please pass the required arguments."
msgstr "پارامترهای نامعتبر ارائه شده است. لطفا آرگومان های مورد نیاز را ارسال کنید."

#: hrms/api/roster.py:40
msgid "Invalid shift filter: {0}"
msgstr ""
msgstr "فیلتر شیفت نامعتبر: {0}"

#. Option for the 'Status' (Select) field in DocType 'Employee Grievance'
#: hrms/hr/doctype/employee_grievance/employee_grievance.json
Expand Down
Loading
Loading