I could not override def validate_employee_role


i try this


doc_events = {
 "user":
     {
        "validate":"my_app.overrides.employee.validate_employee_role"
     }
}

and this

# from erpnext.setup.doctype.employee.employee import validate_employee_role as validate_employee_role
# from my_app.overrides.employee import validate_employee_role as custom_validate_employee_role
# validate_employee_role = custom_validate_employee_role

no way worked

@ejaaz

Can you be more specific than “no way worked”? What were you expecting, and what happened?

Note that setting a method path to doc_events.user.validate won’t override the existing validate method. It will just add an additional method called before the document is saved.

from erpnext.setup.doctype.employee.employee import validate_employee_role as validate_employee_role
from my_app.overrides.employee import validate_employee_role as custom_validate_employee_role
validate_employee_role = custom_validate_employee_role

in this way i were expecting override the original validation but no thing happened
in second way it do like what you mention above “add an additional method called before the document is saved.”
and i want to override it

To override a method you have to use a custom class:

https://docs.frappe.io/framework/user/en/python-api/hooks#override-doctype-class

@peterg but the method is not belong to the class erpnext/erpnext/setup/doctype/employee/employee.py at 912f9bfd8e6c14b47bad052c0b62fb3b6a4d7855 · frappe/erpnext · GitHub

Then you have to override the method that calls it.

as you see

I’m not sure I’m following, but if you’re saying that the method you want to override is called by an event hook defined in hooks.py, I’m afraid I’m not aware of any way to override that.

1 Like