Skip to content

Commit

Permalink
chore: qb instead of raw sql
Browse files Browse the repository at this point in the history
  • Loading branch information
krantheman committed Dec 12, 2023
1 parent 078bc6d commit 378f4be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion hrms/hr/doctype/leave_allocation/leave_allocation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt

cur_frm.add_fetch("employee", "employee_name", "employee_name");
frm.add_fetch("employee", "employee_name", "employee_name");

frappe.ui.form.on("Leave Allocation", {
onload: function (frm) {
Expand Down
20 changes: 12 additions & 8 deletions hrms/hr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.query_builder import DocType
from frappe.utils import (
add_days,
comma_and,
Expand Down Expand Up @@ -377,15 +378,18 @@ def allocate_earned_leaves():
if failed_allocations:
allocations = comma_and([get_link_to_form("Leave Allocation", x) for x in failed_allocations])

hr_managers = frappe.db.sql_list(
"""
SELECT DISTINCT(has_role.parent)
FROM `tabHas Role` has_role LEFT JOIN `tabUser` user
ON has_role.parent = user.name
WHERE has_role.parenttype = 'User' AND user.enabled = 1 AND has_role.role = %s
""",
"HR Manager",
User = DocType("User")
HasRole = DocType("Has Role")
query = (
frappe.qb.from_(HasRole)
.left_join(User)
.on(HasRole.parent == User.name)
.select(HasRole.parent)
.distinct()
.where((HasRole.parenttype == "User") & (User.enabled == 1) & (HasRole.role == "HR Manager"))
)
hr_managers = query.run(pluck=True)

frappe.sendmail(
recipients=hr_managers,
subject=_("Failure of Automatic Allocation of Earned Leaves"),
Expand Down

0 comments on commit 378f4be

Please sign in to comment.