diff --git a/crm/fcrm/doctype/crm_form_script/__init__.py b/crm/fcrm/doctype/crm_form_script/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/crm/fcrm/doctype/crm_form_script/crm_form_script.js b/crm/fcrm/doctype/crm_form_script/crm_form_script.js new file mode 100644 index 00000000..7f6f150e --- /dev/null +++ b/crm/fcrm/doctype/crm_form_script/crm_form_script.js @@ -0,0 +1,8 @@ +// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +// frappe.ui.form.on("CRM Form Script", { +// refresh(frm) { + +// }, +// }); diff --git a/crm/fcrm/doctype/crm_form_script/crm_form_script.json b/crm/fcrm/doctype/crm_form_script/crm_form_script.json new file mode 100644 index 00000000..3fe64b37 --- /dev/null +++ b/crm/fcrm/doctype/crm_form_script/crm_form_script.json @@ -0,0 +1,70 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "prompt", + "creation": "2023-12-28 14:18:09.329868", + "doctype": "DocType", + "engine": "InnoDB", + "field_order": [ + "dt", + "column_break_gboh", + "enabled", + "section_break_xeox", + "script" + ], + "fields": [ + { + "fieldname": "column_break_gboh", + "fieldtype": "Column Break" + }, + { + "fieldname": "section_break_xeox", + "fieldtype": "Section Break" + }, + { + "fieldname": "dt", + "fieldtype": "Link", + "in_list_view": 1, + "label": "DocType", + "options": "DocType", + "reqd": 1 + }, + { + "default": "0", + "fieldname": "enabled", + "fieldtype": "Check", + "label": "Enabled" + }, + { + "fieldname": "script", + "fieldtype": "Code", + "label": "Script", + "options": "JS" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2023-12-28 16:26:39.967069", + "modified_by": "Administrator", + "module": "FCRM", + "name": "CRM Form Script", + "naming_rule": "Set by user", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/crm/fcrm/doctype/crm_form_script/crm_form_script.py b/crm/fcrm/doctype/crm_form_script/crm_form_script.py new file mode 100644 index 00000000..7732a806 --- /dev/null +++ b/crm/fcrm/doctype/crm_form_script/crm_form_script.py @@ -0,0 +1,28 @@ +# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +import frappe +from frappe.model.document import Document + + +class CRMFormScript(Document): + def validate(self): + self.check_if_duplicate() + + def check_if_duplicate(self): + """Check if there is already a script for this doctype""" + if self.dt and self.enabled: + filters = { + "dt": self.dt, + "enabled": 1, + } + if self.name: + filters["name"] = ["!=", self.name] + + if frappe.db.exists("CRM Form Script", filters): + frappe.throw( + frappe._( + "Script already exists for this doctype and is enabled" + ), + frappe.DuplicateEntryError, + ) diff --git a/crm/fcrm/doctype/crm_form_script/test_crm_form_script.py b/crm/fcrm/doctype/crm_form_script/test_crm_form_script.py new file mode 100644 index 00000000..ae222e72 --- /dev/null +++ b/crm/fcrm/doctype/crm_form_script/test_crm_form_script.py @@ -0,0 +1,9 @@ +# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt + +# import frappe +from frappe.tests.utils import FrappeTestCase + + +class TestCRMFormScript(FrappeTestCase): + pass