I am trying to override the create_salary_slips
from the hrms app with a methond in a custom app but I cannot get it to work.
In my hooks.py
file of my custom app, I have the following:
override_whitelisted_methods = {
"hrms.payroll.doctype.payroll_entry.payroll_entry.PayrollEntry.create_salary_slips": "business.paycheck.overrides.payroll_entry.create_salary_slips"
}
And my payroll_entry.py
file is:
import frappe
def create_salary_slips( self ):
frappe.utils.logger.set_log_level( "DEBUG" )
logger = frappe.logger( "debug", allow_site = True, file_count = 50 )
logger.error( "**** HERE ****" )
I am using the logging just to confirm the override is happening before I add the rest. But when I click “Create Salary Slips”, it is still running the original code.
This method is being called from JavaScript with a button click (see below). Could that have anything to do with it?
The method you’re override with is not a whitelisted method… iirc the method in your custom file should also be whitelisted. But since this function is within a class, I’m not sure of the self parameter here. Will the class be sent from the client?
Good catch, but still not working after I added @frappe.whitelist()
:
import frappe
@frappe.whitelist()
def create_salary_slips( self ):
frappe.utils.logger.set_log_level( "DEBUG" )
logger = frappe.logger( "debug", allow_site = True, file_count = 50 )
logger.error( "**** HERE ****" )
This being under a class is throwing me off a little bit. I figured I would cross that bridge after I got the override to at least work. I removed the self just to try but that also didn’t work.
Hi @fiveoaks
I think this function cannot be override, because it’s inside the class.
To override this you need to override the Class or JS
Thanks.
I wonder why there is a @frappe.whitelist()
on the function.
I did think about overriding the JavaScript on the button. How would I go about extending the original class PayrollEntry
so as to avoid having to recreate much of the code?
You could import the “Payroll Entry” class and inherit it in one of your custom class, then just write the same function (create_salary_slips) with the logic you need.
from hrms.payroll.doctype.payroll_entry.payroll_entry import PayrollEntry
class NewPayrollEntry(PayrollEntry):
def create_salary_slips(self):
pass
Then in your hooks.py you need to override the PayrollEntry class with your class.
@frappe.whitelist()
is added because this function is calling from client side.
better way is to override the Payroll Entry Class.
or u can override the JS by removing the standard button and add your custom button and call custom method.
1 Like
Hi @fiveoaks ,
You can check the following repo Override Class Method
In this, I added the testhr.py
file where I write the custom logic in the standard method and override it in the __init__.py
file.