Hi there, @Sangram
I have created a custom button in employee.
What I am trying to implement is that when i click on the button, leave
must be allocated for the particular employee till the end of the fiscal
year from its confirmation date.
Unable to execute syntaxes, Not able to traceback the error.
pasting the code as well for the reference:
The problem i am facing is that the system is unable to fetch data from the fiscal year and it stops the execution after printing med.
It does not enter in the if block as well.
JS Script:
cur_frm.add_custom_button(__(“Allocate Leave”),function(){
frappe.call({
method:“erpnext.hr.doctype.employee.employee.allocate_leave”,
args:{
employee:cur_frm.doc.employee,
conf_date:cur_frm.doc.final_confirmation_date,
leave_type:“Privilege Leave”,
joining_date:cur_frm.doc.date_of_joining
},
callback:function(){frappe.msgprint(“Test”)}
});
});
PY Script:
@frappe.whitelist()
def allocate_leave(employee,conf_date,leave_type,joining_date):
print "Employee="+str(employee)
print "Leave type= "+str(leave_type)
print "joining_date = "+str(joining_date)
carry_forwarded_leaves = 0
cd = getdate(conf_date)
print "Conf_Date: "+str(cd)
fed = frappe.get_value("Fiscal Year", "Fiscal Year", "year_end_date")
print "Fiscal End Date = "+str(fed)
tm = relativedelta(fed,cd).months
print ("Total months = "+ str(tm))
med = cd + relativedelta(day =20)
print "med= "+str(med)
if med < cd:
med +=relativedelta(months=1)
print "MED= "+str(med)
if (med-cd).days < 15:
med= med + relativedelta(months =1)
print "MED= "+str(med)
#for i in range(tm):
#l_a_doc = frappe.new_doc("Leave Allocation")
#l_a_doc.update({'employee':employee,'from_date':med - relativedelta(months=1,day = 21),'to_date':med+relativedelta(months=i),'leave_type':'Privilege Leave','carry_forward':1,'new_leaves_allocated':1.75})
#l_a_doc.save(ignore_permissions = True)
#frappe.db.commit()