Salary Slip Leave Balance and Leave taken

Hi

I am working on the script where I can fetch the data from Employee Paid Leaves, Balance Leaves from the leaves and show it on salary slip, but I am confused from which table I should call and How I should call.

Can anyone give me an example if I want to show the leave balance on Salary Slip then what should be the custom script?

I have already created the custom field name balance leave on salary slip doctype.

Regards,

Hi,
You can use the whitelisted method get_leave_balance_on in leave_application.py
Thanks

you already have a frappe.whitelist function called get_leave_balance_on in leave application

@frappe.whitelist()
def get_leave_balance_on(employee, leave_type, date, allocation_records=None,
		consider_all_leaves_in_the_allocation_period=False)

you can call it :slight_smile:

Hi @Ranjith and @MiM

Thanks for the responses, but as I am not hard core programmer, can you give me an example that where I have to use this code? Currently I am putting it in Steup >> Custom Script>>

But it is giving me some error. Please find the below screen shot, the marked fields I want to fetch

Please let me know how to do this?

Regards

Hi,
Please refer the pages in wiki on how to do client side scripting. Look for how to use frappe.call method to execute sever side methods. Its old, still you should be able to figure out.

Also look into leave_application.js on how the get_leave_balance method is invoked. You will have to do this for all leaves types based on your requirement.

Thanks

First you should know which Leave you wanna get its balance
then in you JS file in onload or refresh event write such code

You Field Name: function(frm) {
			return frappe.call({
				method: "erpnext.hr.doctype.leave_application.leave_application.get_leave_balance_on",
				args: {
					employee: frm.doc.employee,
					date: frm.doc.posting_date,
					leave_type: frm.doc.leave_type,
					consider_all_leaves_in_the_allocation_period: true
				},
				callback: function(r) {
					if (!r.exc && r.message) {
						frm.set_value('You Field Name', r.message);
					}
				}
			});
            }
1 Like

Hi @MiM

I am trying to get the balance leaves on the salary slip, e.g.

See the below report for balance leaves.

Now I want to show this casual leave balance or any leave balance on salary slip custom filed which is Balance Paid Leave, that means if the employee has 3 Casual Leaves and 2 Sick Leaves then the Balance Paid Leaves will be 5.

Apart from that I also want to show the Leave Taken which will be the sum of Casual + Sick + Any other leave on the salary slip Paid Leaves.

Now with your code I was trying to fetch the balance leaves to the shown on balance paid leaves on the salary slip, so as instructed I put the code which is given by you, i.e.

balance_paid_leave: function(frm) {
return frappe.call({
method: “erpnext.hr.doctype.leave_application.leave_application.get_leave_balance_on”,
args: {
employee: frm.doc.employee,
date: frm.doc.posting_date,
leave_type: frm.doc.leave_type,
consider_all_leaves_in_the_allocation_period: true
},
callback: function(r) {
if (!r.exc && r.message) {
frm.set_value(‘balance_paid_leave’, r.message);
}
}
});
}

Please Note: I am putting this code in Setup>>custom Scripts>>New Script

and I am getting the below error,

setup@https://erp.examlpe.com/assets/js/form.min.js?ver=1526302067.0:2693:5
_f.Frm.prototype.setup@https://erp.examlpe.com/assets/js/form.min.js?ver=1526302067.0:172:2
_f.Frm.prototype.refresh@https://erp.examlpe.com/assets/js/form.min.js?ver=1526302067.0:446:4
load@https://erp.examlpe.com/assets/js/form.min.js?ver=1526302067.0:87:3
show_doc/<@https://erp.examlpe.com/assets/js/form.min.js?ver=1526302067.0:73:7
callback@https://erp.examlpe.com/assets/js/desk.min.js?ver=1526302067.0:5516:6
callback@https://erp.examlpe.com/assets/js/desk.min.js?ver=1526302067.0:1437:11
_@https://erp.examlpe.com/assets/js/desk.min.js?ver=1526302067.0:1461:29
frappe.request.call/<@https://erp.examlpe.com/assets/js/desk.min.js?ver=1526302067.0:1562:5
i@https://erp.examlpe.com/assets/frappe/js/lib/jquery/jquery.min.js:2:27146
fireWith@https://erp.examlpe.com/assets/frappe/js/lib/jquery/jquery.min.js:2:27914
z@https://erp.examlpe.com/assets/frappe/js/lib/jquery/jquery.min.js:4:12057
c/<@https://erp.examlpe.com/assets/frappe/js/lib/jquery/jquery.min.js:4:15619

Please suggest what to do, your response will be helpful.

Regards