From a98e94caf12a065cb71a89f7b7306339ce1ba7c4 Mon Sep 17 00:00:00 2001 From: Shllokkk Date: Thu, 15 Jan 2026 17:50:27 +0530 Subject: [PATCH 1/3] feat(doctype): generate controller_tree.js boilerplate for tree doctypes --- frappe/core/doctype/doctype/boilerplate/controller_tree.js | 5 +++++ frappe/core/doctype/doctype/doctype.py | 3 +++ frappe/modules/utils.py | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 frappe/core/doctype/doctype/boilerplate/controller_tree.js diff --git a/frappe/core/doctype/doctype/boilerplate/controller_tree.js b/frappe/core/doctype/doctype/boilerplate/controller_tree.js new file mode 100644 index 0000000000..9fc78986e0 --- /dev/null +++ b/frappe/core/doctype/doctype/boilerplate/controller_tree.js @@ -0,0 +1,5 @@ +// Copyright (c) {year}, {app_publisher} and contributors +// For license information, please see license.txt + +// frappe.treeview_settings["{doctype}"] = {{ +// }}; \ No newline at end of file diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index dc3a785a37..1b9f6b50f8 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -877,6 +877,9 @@ class DocType(Document): make_boilerplate("controller.js", self.as_dict()) # make_boilerplate("controller_list.js", self.as_dict()) + if self.is_tree: + make_boilerplate("controller_tree.js", self.as_dict()) + if self.has_web_view: templates_path = frappe.get_module_path( frappe.scrub(self.module), "doctype", frappe.scrub(self.name), "templates" diff --git a/frappe/modules/utils.py b/frappe/modules/utils.py index 64d2463c2f..404540a32d 100644 --- a/frappe/modules/utils.py +++ b/frappe/modules/utils.py @@ -345,6 +345,7 @@ def get_app_publisher(module: str) -> str: def make_boilerplate(template: str, doc: "Document" | "frappe._dict", opts: dict | "frappe._dict" = None): + # print(template, "template_file_path \n\n\n") target_path = get_doc_path(doc.module, doc.doctype, doc.name) template_name = template.replace("controller", scrub(doc.name)) if template_name.endswith("._py"): @@ -354,6 +355,8 @@ def make_boilerplate(template: str, doc: "Document" | "frappe._dict", opts: dict get_module_path("core"), "doctype", scrub(doc.doctype), "boilerplate", template ) + + if os.path.exists(target_file_path): print(f"{target_file_path} already exists, skipping...") return @@ -400,7 +403,7 @@ def make_boilerplate(template: str, doc: "Document" | "frappe._dict", opts: dict """ controller_body = indent(dedent(controller_body), "\t") - + # print(source, "source \n\n\n") with open(target_file_path, "w") as target, open(template_file_path) as source: template = source.read() controller_file_content = cstr(template).format( @@ -413,6 +416,8 @@ def make_boilerplate(template: str, doc: "Document" | "frappe._dict", opts: dict **opts, custom_controller=controller_body, ) + print("template_file_path \n\n\n", controller_file_content) + # print(controller_file_content) target.write(frappe.as_unicode(controller_file_content)) From eda8edc80824ebef570e87d246f27f90ea913919 Mon Sep 17 00:00:00 2001 From: Shllokkk Date: Thu, 15 Jan 2026 20:12:02 +0530 Subject: [PATCH 2/3] refactor: utils.py --- frappe/modules/utils.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/frappe/modules/utils.py b/frappe/modules/utils.py index 404540a32d..cf2745e64d 100644 --- a/frappe/modules/utils.py +++ b/frappe/modules/utils.py @@ -345,7 +345,6 @@ def get_app_publisher(module: str) -> str: def make_boilerplate(template: str, doc: "Document" | "frappe._dict", opts: dict | "frappe._dict" = None): - # print(template, "template_file_path \n\n\n") target_path = get_doc_path(doc.module, doc.doctype, doc.name) template_name = template.replace("controller", scrub(doc.name)) if template_name.endswith("._py"): @@ -355,8 +354,6 @@ def make_boilerplate(template: str, doc: "Document" | "frappe._dict", opts: dict get_module_path("core"), "doctype", scrub(doc.doctype), "boilerplate", template ) - - if os.path.exists(target_file_path): print(f"{target_file_path} already exists, skipping...") return @@ -403,7 +400,7 @@ def make_boilerplate(template: str, doc: "Document" | "frappe._dict", opts: dict """ controller_body = indent(dedent(controller_body), "\t") - # print(source, "source \n\n\n") + with open(target_file_path, "w") as target, open(template_file_path) as source: template = source.read() controller_file_content = cstr(template).format( @@ -417,7 +414,6 @@ def make_boilerplate(template: str, doc: "Document" | "frappe._dict", opts: dict custom_controller=controller_body, ) print("template_file_path \n\n\n", controller_file_content) - # print(controller_file_content) target.write(frappe.as_unicode(controller_file_content)) From 354f8337e9cc08262ab0b8662e31016e7e4ff970 Mon Sep 17 00:00:00 2001 From: Shllokkk Date: Thu, 15 Jan 2026 22:43:03 +0530 Subject: [PATCH 3/3] fix(doctype): remove debug print statement --- frappe/modules/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/frappe/modules/utils.py b/frappe/modules/utils.py index cf2745e64d..64d2463c2f 100644 --- a/frappe/modules/utils.py +++ b/frappe/modules/utils.py @@ -413,7 +413,6 @@ def make_boilerplate(template: str, doc: "Document" | "frappe._dict", opts: dict **opts, custom_controller=controller_body, ) - print("template_file_path \n\n\n", controller_file_content) target.write(frappe.as_unicode(controller_file_content))