From 378f4be7859a2fe80d5caa4f7d7865d42388b96a Mon Sep 17 00:00:00 2001 From: krantheman Date: Tue, 12 Dec 2023 13:25:21 +0530 Subject: [PATCH] chore: qb instead of raw sql --- .../leave_allocation/leave_allocation.js | 2 +- hrms/hr/utils.py | 20 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/hrms/hr/doctype/leave_allocation/leave_allocation.js b/hrms/hr/doctype/leave_allocation/leave_allocation.js index d91830464d..14832f49c3 100755 --- a/hrms/hr/doctype/leave_allocation/leave_allocation.js +++ b/hrms/hr/doctype/leave_allocation/leave_allocation.js @@ -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) { diff --git a/hrms/hr/utils.py b/hrms/hr/utils.py index 510aeaa2a3..a179fa045b 100644 --- a/hrms/hr/utils.py +++ b/hrms/hr/utils.py @@ -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, @@ -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"),