feat: allow extending doctype dashboards via hooks (develop) (#8336)
* feat: allow overriding dasboards via hooks * fix: allow extending dashboard data in hooks * fix: move logic to generic function * format: added description to hook
This commit is contained in:
parent
7ffd2f4298
commit
355fc4b49e
3 changed files with 15 additions and 4 deletions
|
|
@ -233,4 +233,3 @@ def get_js(path):
|
|||
js = frappe.read_file(path)
|
||||
if js:
|
||||
return render_include(js)
|
||||
|
||||
|
|
|
|||
|
|
@ -408,8 +408,10 @@ class Meta(Document):
|
|||
def get_dashboard_data(self):
|
||||
'''Returns dashboard setup related to this doctype.
|
||||
|
||||
This method will return the `data` property in the
|
||||
`[doctype]_dashboard.py` file in the doctype folder'''
|
||||
This method will return the `data` property in the `[doctype]_dashboard.py`
|
||||
file in the doctype's folder, along with any overrides or extensions
|
||||
implemented in other Frappe applications via hooks.
|
||||
'''
|
||||
data = frappe._dict()
|
||||
try:
|
||||
module = load_doctype_module(self.name, suffix='_dashboard')
|
||||
|
|
@ -418,6 +420,9 @@ class Meta(Document):
|
|||
except ImportError:
|
||||
pass
|
||||
|
||||
for hook in frappe.get_hooks("override_doctype_dashboards", {}).get(self.name, []):
|
||||
data = frappe.get_attr(hook)(data=data)
|
||||
|
||||
return data
|
||||
|
||||
def get_row_template(self):
|
||||
|
|
|
|||
|
|
@ -242,12 +242,19 @@ app_license = "{app_license}"
|
|||
|
||||
# before_tests = "{app_name}.install.before_tests"
|
||||
|
||||
# Overriding Whitelisted Methods
|
||||
# Overriding Methods
|
||||
# ------------------------------
|
||||
#
|
||||
# override_whitelisted_methods = {{
|
||||
# "frappe.desk.doctype.event.event.get_events": "{app_name}.event.get_events"
|
||||
# }}
|
||||
#
|
||||
# each overriding function accepts a `data` argument;
|
||||
# generated from the base implementation of the doctype dashboard,
|
||||
# along with any modifications made in other Frappe apps
|
||||
# override_doctype_dashboards = {{
|
||||
# "Task": "{app_name}.task.get_dashboard_data"
|
||||
# }}
|
||||
|
||||
"""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue