fix: use the correct part for dashboard

This commit is contained in:
sokumon 2025-12-04 14:22:22 +05:30
parent e5b7bab26c
commit fa5784b04b

View file

@ -197,3 +197,63 @@ def remove_orphan_doctypes():
update_progress_bar("Deleting orphaned DocTypes", i, len(orphan_doctypes))
frappe.db.commit()
print()
def remove_orphan_entities():
entites = ["Workspace", "Dashboard", "Page", "Report"]
entity_filter_map = {
"Workspace": {"public": 1},
"Page": {"standard": "Yes"},
"Report": {"is_standard": "Yes"},
"Dashboard": {"is_standard": True},
}
for entity in entites:
print(f"Removing orphan {entity}s")
all_enitities = frappe.get_all(
entity, filters=entity_filter_map.get(entity), fields=["name", "module"]
)
for i, w in enumerate(all_enitities):
if w.module:
try:
module_path = frappe.get_module_path(w.module)
if not check_if_record_exists(
type="module", path=module_path, entity_type=entity, name=w.name, module_name=w.module
):
print(f"Deleting entity {entity} {w.name}")
frappe.delete_doc(entity, w.name, force=True, ignore_missing=True)
update_progress_bar(f"Deleting orphaned {entity}", i, len(all_enitities))
print()
except Exception as e:
print(e)
# save the deleted icons
frappe.db.commit() # nosemgrep
def check_if_record_exists(type=None, path=None, entity_type=None, name=None, module_name=None):
scrubbed_name = frappe.scrub(name.lower())
scrubbed_entity_type = frappe.scrub(entity_type.lower())
if scrubbed_entity_type == "dashboard" and module_name:
scrubbed_entity_type = f"{frappe.scrub(module_name.lower())}_dashboard"
if type == "app":
entity_path = os.path.join(path, scrubbed_entity_type, f"{scrubbed_name}.json")
else:
entity_path = os.path.join(path, scrubbed_entity_type, scrubbed_name, f"{scrubbed_name}.json")
print(entity_path)
return os.path.exists(entity_path)
def delete_duplicate_icons():
# This handles app icons which are renamed. Removes the old entry from db.
for app in frappe.get_installed_apps():
icons = frappe.get_all("Desktop Icon", filters=[{"icon_type": "App"}, {"app": app}], pluck="name")
if len(icons) > 1:
for i in icons:
app_path = frappe.get_app_path(app)
if not check_if_record_exists(type="app", path=app_path, entity_type="Desktop Icon", name=i):
print(f"Deleting icon {i}")
frappe.delete_doc("Desktop Icon", i)
# save the deleted icons
frappe.db.commit() # nosemgrep