From f6cf58fa8c49443b47912639caaa10eb0b065601 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Mon, 22 Jul 2019 15:32:41 +0530 Subject: [PATCH] fix: change get all to sql list --- .../leave_ledger_entry/leave_ledger_entry.py | 18 ++++++++++-------- erpnext/hr/doctype/leave_type/leave_type.py | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.py b/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.py index 99a9d0d933b..0520b867f27 100644 --- a/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.py +++ b/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.py @@ -20,14 +20,16 @@ class LeaveLedgerEntry(Document): def validate_leave_allocation_against_leave_application(ledger): ''' Checks that leave allocation has no leave application against it ''' - leave_application_records = frappe.get_all("Leave Ledger Entry", - filters={ - 'employee': ledger.employee, - 'leave_type': ledger.leave_type, - 'transaction_type': 'Leave Application', - 'from_date': (">=", ledger.from_date), - 'to_date': ('<=', ledger.to_date) - }, fields=['transaction_name']) + leave_application_records = frappe.db.sql_list(""" + SELECT transaction_name + FROM `tabLeave Application` + WHERE + employee=%s, + leave_type=%s, + transaction_type='Leave Application', + from_date>=%s, + to_date<=%s + """, (ledger.employee, ledger.leave_type, ledger.from_date, ledger.to_date)) if leave_application_records: frappe.throw(_("Leave allocation %s is linked with leave application %s" diff --git a/erpnext/hr/doctype/leave_type/leave_type.py b/erpnext/hr/doctype/leave_type/leave_type.py index cbc67817833..75336e0c7e4 100644 --- a/erpnext/hr/doctype/leave_type/leave_type.py +++ b/erpnext/hr/doctype/leave_type/leave_type.py @@ -12,6 +12,6 @@ from frappe.model.document import Document class LeaveType(Document): def validate(self): if self.is_lwp: - leave_allocation = frappe.get_doc("Leave Allocation", {"leave_type": self.name}, ['name']) + leave_allocation = frappe.db.sql_list("""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