I wrote an validate
hook in my app, but it didn’t work, How to debug it?
How to know which hooks are binding to the doctypes?
@nnylyj do you can list all hooks, using the bellow code
frappe.get_hooks('doc_events').get('DocType').get('validate')
frappe.get_hooks('doc_events').get('*').get('validate')
Thanks!
I get the result but it’s weired.
I bind validate
hooks on Purchase Order
and Sales Order
and a before_save
on Item Price
, but ONLY Item Price
hooked successfully.
'doc_events': {u'Item Price': {u'before_save': [u'dmallerp.item_price_log.logger.create_item_price_log']},
u'Purchase Order': {u'validate': [u'dmallerp.validators.hooks.validate_return_order_qty']},
u'Sales Order': {u'validate': [u'dmallerp.validators.hooks.validate_return_order_qty']}}
using frappe.get_hooks('doc_events')
and got
{u'*': {u'after_insert': [u'frappe.email.doctype.email_alert.email_alert.trigger_email_alerts'],
u'after_rename': [u'frappe.desk.notifications.clear_doctype_notifications'],
u'on_cancel': [u'frappe.desk.notifications.clear_doctype_notifications',
u'frappe.email.doctype.email_alert.email_alert.trigger_email_alerts'],
u'on_submit': [u'frappe.email.doctype.email_alert.email_alert.trigger_email_alerts',
u'frappe.desk.doctype.feed.feed.update_feed'],
u'on_trash': [u'frappe.desk.notifications.clear_doctype_notifications'],
u'on_update': [u'frappe.desk.notifications.clear_doctype_notifications',
u'frappe.email.doctype.email_alert.email_alert.trigger_email_alerts',
u'frappe.desk.doctype.feed.feed.update_feed'],
u'validate': [u'frappe.email.doctype.email_alert.email_alert.trigger_email_alerts']},
u'Address': {u'validate': [u'erpnext.shopping_cart.cart.set_customer_in_address']},
---LOOK_AT_HERE--> u'Item Price': {u'before_save': [u'dmallerp.item_price_log.logger.create_item_price_log']},
u'Price List': {u'on_update': [u'erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings.validate_cart_settings']},
u'Sales Taxes and Charges Template': {u'on_update': [u'erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings.validate_cart_settings']},
u'Stock Entry': {u'on_cancel': [u'erpnext.stock.doctype.material_request.material_request.update_completed_and_requested_qty'],
u'on_submit': [u'erpnext.stock.doctype.material_request.material_request.update_completed_and_requested_qty']},
u'User': {u'on_update': [u'erpnext.hr.doctype.employee.employee.update_user_permissions'],
u'validate': [u'erpnext.hr.doctype.employee.employee.validate_employee_role']}}
And,
u'Purchase Order': {u'validate': [u'dmallerp.validators.hooks.validate_return_order_qty']},
u'Sales Order': {u'validate': [u'dmallerp.validators.hooks.validate_return_order_qty']}}
LOST?
@nnylyj pass app_name="your_app_name"
, to get only the hooks of your app!
The result is showing all hooks in the environment
Yeah, I mean hooks were exactly defined in my app, but not shown in environment.
So, just pass
frappe.get_hooks('doc_events', app_name="dmallerp").get('*').get('validate')
You need to go to user menu and click on “Reload”. It will clear frappe’s cache where hooks are cached.
You can also do that from the command line using:
bench --site SITENAME clear-cache
In [27]: frappe.get_hooks('doc_events', app_name="dmallerp").get('*').get('validate')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/home/ubuntu/frappe-bench/env/local/lib/python2.7/site-packages/frappe-6.18.1-py2.7.egg/frappe/commands.pyc in <module>()
----> 1 frappe.get_hooks('doc_events', app_name="dmallerp").get('*').get('validate')
AttributeError: 'NoneType' object has no attribute 'get'
Replace the “*” by the doctype names, or store frappe.get_hook
in a variable, and inspect it