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): def validate_leave_allocation_against_leave_application(ledger):
''' Checks that leave allocation has no leave application against it ''' ''' Checks that leave allocation has no leave application against it '''
leave_application_records = frappe.get_all("Leave Ledger Entry", leave_application_records = frappe.db.sql_list("""
filters={ SELECT transaction_name
'employee': ledger.employee, FROM `tabLeave Application`
'leave_type': ledger.leave_type, WHERE
'transaction_type': 'Leave Application', employee=%s,
'from_date': (">=", ledger.from_date), leave_type=%s,
'to_date': ('<=', ledger.to_date) transaction_type='Leave Application',
}, fields=['transaction_name']) from_date>=%s,
to_date<=%s
""", (ledger.employee, ledger.leave_type, ledger.from_date, ledger.to_date))
if leave_application_records: if leave_application_records:
frappe.throw(_("Leave allocation %s is linked with leave application %s" 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): class LeaveType(Document):
def validate(self): def validate(self):
if self.is_lwp: 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: 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 frappe.throw(_("""Leave application is linked with leave allocations {0}. Leave application cannot be set as leave without pay""").format(", ".join(leave_allocation))) #nosec