Adding hooks from another app

Hi ,

i wondering how i can use hooks to call method on another app ,let say i want to edit hooks.py in erpnext when validate sales order i want to call my validate fucntion that has in my new app let said that costing

there is no example in hooks.py so i confused how i can do this, all function called is under erpnext apps

THanks

You have to edit hooks.py of your own app - not erpnext. add a doc_events hook:

doc_events = {"Sales Order": {"validate":"myapp.module"}}

Thanks, ill try it, anyway for better understanding what was the variable that passed on hooks function , i see there is doc and method , what was doc value and method value?

Thanks

doc is the doc object on which the event occoured
method is the the lifecycle method that was called (ie. validate, before_insert, on_update, etc)

Hi, is there any documentation to show us list of documentation ?..
im tried to add before_cancel but its not called…
doc_events = {
“Journal Voucher”: {
“on_submit”: “accounting_addons.giro.doctype.giro.giro.on_jv_update”,
“before_cancel”: “accounting_addons.giro.doctype.giro.giro.on_trash_jv”
}
}
and here my fucntion

def on_trash_jv(doc,method):
frappe.throw(“”" on thrash called “”")

1 Like

https://frappe.io/docs/user-guide/hooks

1 Like

Hi,

From there what i do is looks alright…because the on_sumbit functionis called,but why the before_cancel is not called ?
is there anyway to trace it ? or do you know why?

Thanks

Solved…found the problem…i need to update the frappe version…thanks

1 Like