fix: fetch queries

This commit is contained in:
Mangesh-Khairnar
2019-05-28 13:24:15 +05:30
parent 9d6151d200
commit ae4228aed4

View File

@@ -49,6 +49,7 @@ def generate_encashment_leave_ledger_entries(allocation_list):
def get_allocation_records(): def get_allocation_records():
return frappe.db.sql(""" return frappe.db.sql("""
WITH allocation_values AS (
SELECT SELECT
DISTINCT name, DISTINCT name,
employee, employee,
@@ -58,8 +59,16 @@ def get_allocation_records():
from_date, from_date,
to_date, to_date,
carry_forward, carry_forward,
RANK() OVER(PARTITION BY employee, leave_type ORDER BY to_date DESC) as allocation RANK() OVER(
PARTITION BY employee, leave_type
ORDER BY to_date DESC
) as allocation
FROM `tabLeave Allocation` FROM `tabLeave Allocation`
)
SELECT
*
FROM
`allocation_values`
WHERE WHERE
allocation=1 allocation=1
""", as_dict=1) """, as_dict=1)
@@ -67,7 +76,7 @@ def get_allocation_records():
def get_leaves_application_records(allocation_list): def get_leaves_application_records(allocation_list):
leave_applications = [] leave_applications = []
for allocation in allocation_list: for allocation in allocation_list:
leave_applications.append(frappe.db.sql(""" leave_applications += frappe.db.sql("""
SELECT SELECT
DISTINCT name, DISTINCT name,
employee, employee,
@@ -78,15 +87,15 @@ def get_leaves_application_records(allocation_list):
FROM `tabLeave Application` FROM `tabLeave Application`
WHERE WHERE
from_date >= %s from_date >= %s
leave_type = %s AND leave_type = %s
employee = %s AND employee = %s
""", (allocation.from_date, allocation.leave_type, allocation.employee))) """, (allocation.from_date, allocation.leave_type, allocation.employee))
return leave_applications return leave_applications
def get_leave_encashment_records(allocation_list): def get_leave_encashment_records(allocation_list):
leave_encashments = [] leave_encashments = []
for allocation in allocation_list: for allocation in allocation_list:
leave_encashments.append(frappe.db.sql(""" leave_encashments += frappe.db.sql("""
SELECT SELECT
DISTINCT name, DISTINCT name,
employee, employee,
@@ -97,6 +106,7 @@ def get_leave_encashment_records(allocation_list):
FROM `tabLeave Encashment` FROM `tabLeave Encashment`
WHERE WHERE
leave_type = %s leave_type = %s
employee = %s AND employee = %s
""", (allocation.leave_type, allocation.employee))) AND encashment_date >= %s
""", (allocation.leave_type, allocation.employee, allocation.from_date))
return leave_encashments return leave_encashments