fix: change get all to sql list

This commit is contained in:
Mangesh-Khairnar 2019-07-22 15:32:41 +05:30
parent cbc22e6369
commit f6cf58fa8c
2 changed files with 11 additions and 9 deletions

View File

@ -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"

View File

@ -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