Merge pull request #14028 from rohitwaghchaure/get_approved_leaves_for_period_issue

[Fix] get_approved_leaves_for_period module import failed
This commit is contained in:
rohitwaghchaure 2018-05-14 21:39:09 +05:30 committed by GitHub
commit 4f2e39cd09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -538,4 +538,39 @@ def get_mandatory_approval(doctype):
'expense_approver_mandatory_in_expense_claim')
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