ERPNext Foundation ERPNext Cloud Chat Blog Discuss Frappé* Donate

Change to how hooks.py works?


#1

I have a custom app that uses doc_events to override the validation method of a particular doctype (Payment Entry). On the develop branch, until recently, it worked fine, but suddenly it’s not working. My override method gets called, but so does the original.

My code looks like this:

#in hooks.py
doc_events = {
	"Payment Entry": {"validate":"{path.to.custom.app}.utils.custom_payment_entry_validation"}
}

then…

#in utils.py
def custom_payment_entry_validation(doc,method):
	print("Called")
	doc.validate = validate
	doc.validate(doc)
def validate(self):
	print("Overridden")

Both “Called” and “Overridden” show up in the console as I’d hoped, but the original validate method gets called as well on top of everything else.

Any suggestions?


#2

This is by design from the starting, it never override the existing method, doc_events extend the existing method.


#5

Hello

Please refer the below link. May be use full to you.

https://frappe.io/docs/user/en/guides/basics/hooks

Thanks