ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Override all save function in all doctype


#1

Hello, any method to override all “before save” method on every doctype?
Let say, I want to create pop up (done/success) when I press save button on the new item (doctype).


#2

since all doctype inherit from Document, maybe create your custom Document class which inherits Document itself. Then make all your docs inherits it instead.

Never done this myself though.


#3

Have you tried hooks?

https://frappe.io/docs/user/en/guides/basics/hooks#crud-events


#4

i think that is what i need,
do you have tutorial step by step to create/setting hook?


#5

in erpnext/hooks.py

Ex: You need to call a method when before save Sales Invoice.
Assuming you have a custom app, call custom_erp

doc_events = {
	"Sales Invoice": {
		"before_save": "custom_erp.filename.method_name"
	}
}

Your method

def method_name(doc, method):
    # doc is sales invoice doc

#6

wow great thank you very much,
any idea how to call javascript method inside python?
ex:
i want to call alert in hook after_save


#7

try this:

frappe.msgprint(“string”)


#8

thank you so much, i will try it