fix(patch): create new docs for customized standard dashboards
This commit is contained in:
parent
72615449db
commit
e6a986559e
3 changed files with 68 additions and 1 deletions
|
|
@ -292,4 +292,5 @@ execute:frappe.delete_doc("DocType", "Onboarding Slide Field")
|
|||
execute:frappe.delete_doc("DocType", "Onboarding Slide Help Link")
|
||||
frappe.patches.v13_0.update_date_filters_in_user_settings
|
||||
frappe.patches.v13_0.update_duration_options
|
||||
frappe.patches.v13_0.replace_old_data_import # 2020-06-24
|
||||
frappe.patches.v13_0.replace_old_data_import # 2020-06-24
|
||||
frappe.patches.v13_0.create_custom_dashboards_cards_and_charts
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
import frappe
|
||||
import json
|
||||
from frappe.model.naming import append_number_if_name_exists
|
||||
from frappe.utils.dashboard import get_dashboards_with_link
|
||||
|
||||
def execute():
|
||||
if not frappe.db.table_exists('Dashboard Chart')\
|
||||
or not frappe.db.table_exists('Number Card')\
|
||||
or not frappe.db.table_exists('Dashboard'):
|
||||
return
|
||||
|
||||
frappe.reload_doc('desk', 'doctype', 'dashboard_chart')
|
||||
frappe.reload_doc('desk', 'doctype', 'number_card')
|
||||
frappe.reload_doc('desk', 'doctype', 'dashboard')
|
||||
|
||||
modified_charts = get_modified_docs('Dashboard Chart')
|
||||
modified_cards = get_modified_docs('Number Card')
|
||||
modified_dashboards = [doc.name for doc in get_modified_docs('Dashboard')]
|
||||
|
||||
for chart in modified_charts:
|
||||
modified_dashboards += get_dashboards_with_link(chart.name, 'Dashboard Chart')
|
||||
rename_modified_doc(chart.name, 'Dashboard Chart')
|
||||
|
||||
for card in modified_cards:
|
||||
modified_dashboards += get_dashboards_with_link(card.name, 'Number Card')
|
||||
rename_modified_doc(card.name, 'Number Card')
|
||||
|
||||
modified_dashboards = list(set(modified_dashboards))
|
||||
|
||||
for dashboard in modified_dashboards:
|
||||
rename_modified_doc(dashboard, 'Dashboard')
|
||||
|
||||
def get_modified_docs(doctype):
|
||||
return frappe.get_all(doctype,
|
||||
filters = {
|
||||
'owner': 'Administrator',
|
||||
'modified_by': ['!=', 'Administrator']
|
||||
})
|
||||
|
||||
def rename_modified_doc(docname, doctype):
|
||||
new_name = docname + ' Custom'
|
||||
try:
|
||||
frappe.rename_doc(doctype, docname, new_name)
|
||||
except:
|
||||
new_name = append_number_if_name_exists(doctype, new_name)
|
||||
frappe.rename_doc(doctype, docname, new_name)
|
||||
|
|
@ -76,6 +76,26 @@ def get_from_date_from_timespan(to_date, timespan):
|
|||
return add_to_date(to_date, years=years, months=months, days=days,
|
||||
as_datetime=True)
|
||||
|
||||
def get_dashboards_with_link(docname, doctype):
|
||||
dashboards = []
|
||||
links = []
|
||||
|
||||
if doctype == 'Dashboard Chart':
|
||||
links = frappe.get_all('Dashboard Chart Link',
|
||||
fields = ['parent'],
|
||||
filters = {
|
||||
'chart': docname
|
||||
})
|
||||
elif doctype == 'Number Card':
|
||||
links = frappe.get_all('Number Card Link',
|
||||
fields = ['parent'],
|
||||
filters = {
|
||||
'card': docname
|
||||
})
|
||||
|
||||
dashboards = [link.parent for link in links]
|
||||
return dashboards
|
||||
|
||||
def sync_dashboards(app=None):
|
||||
"""Import, overwrite fixtures from `[app]/fixtures`"""
|
||||
if not cint(frappe.db.get_single_value('System Settings', 'setup_complete')):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue