fix: fetch queries
This commit is contained in:
parent
9d6151d200
commit
ae4228aed4
@ -49,17 +49,26 @@ 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
|
||||||
|
DISTINCT name,
|
||||||
|
employee,
|
||||||
|
leave_type,
|
||||||
|
new_leaves_allocated,
|
||||||
|
carry_forwarded_leaves,
|
||||||
|
from_date,
|
||||||
|
to_date,
|
||||||
|
carry_forward,
|
||||||
|
RANK() OVER(
|
||||||
|
PARTITION BY employee, leave_type
|
||||||
|
ORDER BY to_date DESC
|
||||||
|
) as allocation
|
||||||
|
FROM `tabLeave Allocation`
|
||||||
|
)
|
||||||
SELECT
|
SELECT
|
||||||
DISTINCT name,
|
*
|
||||||
employee,
|
FROM
|
||||||
leave_type,
|
`allocation_values`
|
||||||
new_leaves_allocated,
|
|
||||||
carry_forwarded_leaves,
|
|
||||||
from_date,
|
|
||||||
to_date,
|
|
||||||
carry_forward,
|
|
||||||
RANK() OVER(PARTITION BY employee, leave_type ORDER BY to_date DESC) as allocation
|
|
||||||
FROM `tabLeave Allocation`
|
|
||||||
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
|
||||||
Loading…
x
Reference in New Issue
Block a user