[Fix] get_approved_leaves_for_period module import failed
This commit is contained in:
parent
2ca83d61ea
commit
9ba72f7897
@ -538,4 +538,39 @@ def get_mandatory_approval(doctype):
|
|||||||
'expense_approver_mandatory_in_expense_claim')
|
'expense_approver_mandatory_in_expense_claim')
|
||||||
|
|
||||||
return mandatory
|
return mandatory
|
||||||
|
|
||||||
|
def get_approved_leaves_for_period(employee, leave_type, from_date, to_date):
|
||||||
|
query = """
|
||||||
|
select employee, leave_type, from_date, to_date, total_leave_days
|
||||||
|
from `tabLeave Application`
|
||||||
|
where employee=%(employee)s
|
||||||
|
and docstatus=1
|
||||||
|
and (from_date between %(from_date)s and %(to_date)s
|
||||||
|
or to_date between %(from_date)s and %(to_date)s
|
||||||
|
or (from_date < %(from_date)s and to_date > %(to_date)s))
|
||||||
|
"""
|
||||||
|
if leave_type:
|
||||||
|
query += "and leave_type=%(leave_type)s"
|
||||||
|
|
||||||
|
leave_applications = frappe.db.sql(query,{
|
||||||
|
"from_date": from_date,
|
||||||
|
"to_date": to_date,
|
||||||
|
"employee": employee,
|
||||||
|
"leave_type": leave_type
|
||||||
|
}, as_dict=1)
|
||||||
|
|
||||||
|
leave_days = 0
|
||||||
|
for leave_app in leave_applications:
|
||||||
|
if leave_app.from_date >= getdate(from_date) and leave_app.to_date <= getdate(to_date):
|
||||||
|
leave_days += leave_app.total_leave_days
|
||||||
|
else:
|
||||||
|
if leave_app.from_date < getdate(from_date):
|
||||||
|
leave_app.from_date = from_date
|
||||||
|
if leave_app.to_date > getdate(to_date):
|
||||||
|
leave_app.to_date = to_date
|
||||||
|
|
||||||
|
leave_days += get_number_of_leave_days(employee, leave_type,
|
||||||
|
leave_app.from_date, leave_app.to_date)
|
||||||
|
|
||||||
|
return leave_days
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user