From 7b32b96cfc65b80cf59e268c17d464be4c24b15f Mon Sep 17 00:00:00 2001 From: sokumon Date: Sun, 7 Dec 2025 21:35:10 +0530 Subject: [PATCH] fix: handle names with parenthesis --- .../desk/doctype/desktop_icon/desktop_icon.py | 2 ++ frappe/migrate.py | 3 +++ frappe/model/sync.py | 26 ++++++++++++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/frappe/desk/doctype/desktop_icon/desktop_icon.py b/frappe/desk/doctype/desktop_icon/desktop_icon.py index de7e3b082d..587e3b7312 100644 --- a/frappe/desk/doctype/desktop_icon/desktop_icon.py +++ b/frappe/desk/doctype/desktop_icon/desktop_icon.py @@ -697,6 +697,7 @@ def create_desktop_icons_from_workspace(): if w.module: app_name = w.app or frappe.db.get_value("Module Def", w.module, "app_name") if app_name in frappe.get_installed_apps(): + icon.app_name = app_name app_title = frappe.get_hooks("app_title", app_name=app_name)[0] app_icon = frappe.db.exists("Desktop Icon", {"label": app_title, "icon_type": "App"}) if app_icon: @@ -744,6 +745,7 @@ def create_desktop_icons_from_installed_apps(): icon.standard = 1 icon.idx = index icon.icon_type = "App" + icon.app = a icon.link = app_details[0]["route"] icon.logo_url = app_details[0]["logo"] if not frappe.db.exists("Desktop Icon", [{"label": icon.label, "icon_type": icon.icon_type}]): diff --git a/frappe/migrate.py b/frappe/migrate.py index 623fa1bcbe..87287408bc 100644 --- a/frappe/migrate.py +++ b/frappe/migrate.py @@ -182,6 +182,9 @@ class SiteMigration: print("Removing orphan doctypes...") frappe.model.sync.remove_orphan_doctypes() + frappe.model.sync.remove_orphan_entities() + frappe.model.sync.delete_duplicate_icons() + print("Syncing portal menu...") frappe.get_single("Portal Settings").sync_menu() diff --git a/frappe/model/sync.py b/frappe/model/sync.py index 825bb718e4..5bdacd29f9 100644 --- a/frappe/model/sync.py +++ b/frappe/model/sync.py @@ -6,6 +6,7 @@ perms will get synced only if none exist """ import os +import re import frappe from frappe.cache_manager import clear_controller_cache @@ -235,12 +236,25 @@ def check_if_record_exists(type=None, path=None, entity_type=None, name=None, mo 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 build_path(entity_name): + if type == "app": + return os.path.join(path, scrubbed_entity_type, f"{entity_name}.json") + return os.path.join(path, scrubbed_entity_type, entity_name, f"{entity_name}.json") + + entity_path = build_path(scrubbed_name) + if os.path.exists(entity_path): + return True + + # This will handle names with brackets Eg: Item Balance (Simple) + if "(" in name: + cleaned_name = re.sub(r"\s*\([^)]*\)", "", name) + scrubbed_cleaned = frappe.scrub(cleaned_name) + cleaned_path = build_path(scrubbed_cleaned) + if os.path.exists(cleaned_path): + return True + + return False def delete_duplicate_icons():