How to call a python function not whitelist

I want to extend salary slip functionality so I tried to call get_emp_and_leave_details

 		frappe.call({
				"method": "erpnext.erpnext.hr.doctype.salary_slip.salary_slip.SalarySlip.get_emp_and_leave_details",
		args: {
			docs: frm.doc
				} ,
				callback: function (data) {
					console.log(data);
				}
		});

but it gives me an error:

The resource you are looking for is not available

I know it is not whitelisted. but is there a workaround to call not whitelist function in the custom app?

Since you are building a custom app, can think of making a whitelisted api function and call SalarySlip.get_emp_and_leave_details from there.
In custom app…

@frappe.whitelist()
def get_emp_and_leave_details(dt, dn)
    doc = frappe.get_doc(dt, dn)
    from erpnext.erpnext.hr.doctype.salary_slip.salary_slip.SalarySlip import get_emp_and_leave_details
    doc.get_emp_and_leave_details()
1 Like
$c('runserverobj', { 'method': 'get_emp_and_leave_details', 'docs': doc }, callback);
};

I haven’t tested it. Hope it helps.

@vijaywm Thank you for your reply but is not working, I tried this before and give this error:

 from erpnext.erpnext.hr.doctype.salary_slip.salary_slip.SalarySlip import get_emp_and_leave_details
ImportError: No module named erpnext.hr.doctype.salary_slip.salary_slip.SalarySlip

try this

frappe.call({
	method:"get_emp_and_leave_details",
	doc:frm.doc, // place doc here
	args: {
		// no need for docs: frm.doc here.
	},
	callback:function (r) {
		console.log(r);
	}
});

@revant_one I am sorry for the confusion .
I am trying to call get_emp_and_leave_details from custom js doctype, not from salary_slip.js

Thanks @revant_one. That works great. (in a different scenario…not related to hr)

@Mohammed_Redha Did you get it working ? I suppose it can be called from any custom doctype js, within desk.

1 Like

@vijaywm No , it is not working for me :disappointed_relieved:

@vijaywm Thank you so much

I tried without import:

   @frappe.whitelist()
    def get_emp_and_leave_details(self):
        doc = frappe.get_doc(self.doctype, self.name)
        doc.get_emp_and_leave_details()  

and working like a charm :sunglasses:

2 Likes