From 5fb2bfab4b991ab812d07da315a4c0e422b6049a Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 12 Apr 2022 13:22:32 +0530 Subject: [PATCH] feat: allow multiple client scripts --- .../doctype/client_script/client_script.json | 5 ++++- .../custom/doctype/client_script/client_script.py | 14 -------------- frappe/desk/form/meta.py | 14 +++++++++++--- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/frappe/custom/doctype/client_script/client_script.json b/frappe/custom/doctype/client_script/client_script.json index eca84b4dec..1db4dfe160 100644 --- a/frappe/custom/doctype/client_script/client_script.json +++ b/frappe/custom/doctype/client_script/client_script.json @@ -1,6 +1,7 @@ { "actions": [], "allow_import": 1, + "autoname": "Prompt", "creation": "2013-01-10 16:34:01", "description": "Adds a custom client script to a DocType", "doctype": "DocType", @@ -52,6 +53,7 @@ "default": "Form", "fieldname": "view", "fieldtype": "Select", + "in_list_view": 1, "label": "Apply To", "options": "List\nForm", "set_only_once": 1 @@ -75,10 +77,11 @@ "idx": 1, "index_web_pages_for_search": 1, "links": [], - "modified": "2022-02-18 00:43:33.941466", + "modified": "2022-04-12 12:48:15.717985", "modified_by": "Administrator", "module": "Custom", "name": "Client Script", + "naming_rule": "Set by user", "owner": "Administrator", "permissions": [ { diff --git a/frappe/custom/doctype/client_script/client_script.py b/frappe/custom/doctype/client_script/client_script.py index 3039e0a4a5..b60f5708d1 100644 --- a/frappe/custom/doctype/client_script/client_script.py +++ b/frappe/custom/doctype/client_script/client_script.py @@ -6,20 +6,6 @@ from frappe.model.document import Document class ClientScript(Document): - def autoname(self): - self.name = f"{self.dt}-{self.view}" - - def validate(self): - if not self.is_new(): - return - - exists = frappe.db.exists("Client Script", {"dt": self.dt, "view": self.view}) - if exists: - frappe.throw( - _("Client Script for {0} {1} already exists").format(frappe.bold(self.dt), self.view), - frappe.DuplicateEntryError, - ) - def on_update(self): frappe.clear_cache(doctype=self.dt) diff --git a/frappe/desk/form/meta.py b/frappe/desk/form/meta.py index ba19377c48..f5edd3fcc6 100644 --- a/frappe/desk/form/meta.py +++ b/frappe/desk/form/meta.py @@ -155,7 +155,7 @@ class FormMeta(Meta): frappe.db.get_all( "Client Script", filters={"dt": self.name, "enabled": 1}, - fields=["script", "view"], + fields=["name", "script", "view"], order_by="creation asc", ) or "" @@ -165,10 +165,18 @@ class FormMeta(Meta): form_script = "" for script in client_scripts: if script.view == "List": - list_script += script.script + list_script += f""" +// {script.name} +{script.script} + +""" if script.view == "Form": - form_script += script.script + form_script += f""" +// {script.name} +{script.script} + +""" file = scrub(self.name) form_script += f"\n\n//# sourceURL={file}__custom_js"