List of Hooks
Here’s a categorized list of hooks that can be defined in a Frappe application, based on typical usage:
Core Hooks
app_name- Name of the application.app_title- Title of the application.app_publisher- Publisher of the application.app_description- Short description of the application.app_icon- Icon for the application.app_color- Primary color for the application.app_email- Support email for the application.app_version- Version of the application.required_apps- List of dependent Frappe apps.
DocType Hooks
doctype_js- Map of JavaScript files for specific DocTypes.- Example:
{'Sales Invoice': 'public/js/sales_invoice.js'}
- Example:
doctype_list_js- JavaScript for the list view of a DocType.doctype_tree_js- JavaScript for the tree view of a DocType.doctype_calendar_js- JavaScript for the calendar view of a DocType.override_doctype_class- Override the Python class for a DocType.- Example:
{'ToDo': 'custom_app.overrides.CustomToDo'}
- Example:
Document Events
doc_events- Hooks for specific DocType events (CRUD operations).- Events:
on_update,before_save,after_insert,on_trash,on_submit,on_cancel, etc. - Example:
{ "Sales Invoice": { "on_submit": "custom_app.events.sales_invoice_on_submit", } }
- Events:
Scheduled Tasks
scheduler_events- Define periodic tasks.- Example:
scheduler_events = { "all": [ "custom_app.tasks.all" ], "daily": [ "custom_app.tasks.daily" ], "hourly": [ "custom_app.tasks.hourly" ], "weekly": [ "custom_app.tasks.weekly" ], "monthly": [ "custom_app.tasks.monthly" ] }
- Example:
Permission Hooks
permission_query_conditions- Define custom permission conditions for a DocType.has_permission- Define custom logic to check if a user has access to a DocType.
Override Hooks
override_whitelisted_methods- Override standard Frappe whitelisted methods.- Example:
override_whitelisted_methods = { "frappe.desk.doctype.event.event.get_events": "custom_app.custom_event.get_events" }
- Example:
override_doctype_dashboards- Override the dashboard for a DocType.override_doctype_class- Replace the Python class of a DocType.
Notification Hooks
notification_config- Define a custom notification configuration.- Example:
notification_config = "custom_app.notifications.get_notification_config"
- Example:
Custom Jinja Filters
jinja- Define custom filters for Jinja templating.- Example:
jinja = { "filters": "custom_app.utils.jinja_filters" }
- Example:
Auth Hooks
auth_hooks- Add custom authentication logic.- Example:
auth_hooks = ["custom_app.auth.validate"]
- Example:
Fixtures
fixtures- Define DocTypes or customizations to export as fixtures.- Example:
fixtures = [ "Custom Field", "Property Setter" ]
- Example:
Translation Hooks
translated_search_doctypes- Specify DocTypes where translations should be searchable.
Page and Report Hooks
page_js- JavaScript for specific pages.report_js- JavaScript for specific reports.
Website Hooks
website_context- Add context for website rendering.update_website_context- Update global website context.
Other Miscellaneous Hooks
on_session_creation- Logic to run when a user session is created.before_tests- Logic to run before tests are executed.task_fail- Logic to handle task failure.before_migrate/after_migrate- Logic to run during migration.user_data_fields- Define sensitive fields for data protection.