From 107b2768fd1a585f1ca83d1aad202751c426f3ca Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Wed, 14 Aug 2019 16:09:16 +0530 Subject: [PATCH] refactor: replace raw sql with orm --- erpnext/hr/doctype/leave_type/leave_type.py | 9 ++++++++- erpnext/hr/utils.py | 1 - 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/erpnext/hr/doctype/leave_type/leave_type.py b/erpnext/hr/doctype/leave_type/leave_type.py index 3a19fa98e6c..598bff2f13e 100644 --- a/erpnext/hr/doctype/leave_type/leave_type.py +++ b/erpnext/hr/doctype/leave_type/leave_type.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import calendar import frappe from datetime import datetime +from frappe.utils import today from frappe import _ from frappe.model.document import Document @@ -12,6 +13,12 @@ from frappe.model.document import Document class LeaveType(Document): def validate(self): if self.is_lwp: - leave_allocation = frappe.db.sql_list("""select name from `tabLeave Allocation` where leave_type=%s""", (self.name)) + leave_allocation = frappe.get_all("Leave Allocation", filters={ + 'leave_type': self.name, + 'from_date': ("<=", today()), + 'to_date': (">=", today()) + }, ['name']) + leave_allocation = [l['name'] for l in leave_allocation] + frappe.db("""select name from `tabLeave Allocation` where leave_type=%s""", (self.name)) if leave_allocation: frappe.throw(_('Leave application is linked with leave allocations {0}. Leave application cannot be set as leave without pay').format(", ".join(leave_allocation))) #nosec \ No newline at end of file diff --git a/erpnext/hr/utils.py b/erpnext/hr/utils.py index 2183c5e678b..1464a779368 100644 --- a/erpnext/hr/utils.py +++ b/erpnext/hr/utils.py @@ -323,7 +323,6 @@ def allocate_earned_leaves(): allocation.db_set("total_leaves_allocated", new_allocation, update_modified=False) create_earned_leave_ledger_entry(allocation, earned_leaves, today) - def create_earned_leave_ledger_entry(allocation, earned_leaves, date): ''' Create leave ledger entry based on the earned leave frequency ''' allocation.new_leaves_allocated = earned_leaves