fix: allow adding multiple form script
This commit is contained in:
parent
951efb2ea9
commit
8c3b1b7d25
@ -6,27 +6,7 @@ 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,
|
||||
"view": self.view,
|
||||
"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,
|
||||
)
|
||||
pass
|
||||
|
||||
def get_form_script(dt, view="Form"):
|
||||
"""Returns the form script for the given doctype"""
|
||||
@ -37,11 +17,10 @@ def get_form_script(dt, view="Form"):
|
||||
.where(FormScript.dt == dt)
|
||||
.where(FormScript.view == view)
|
||||
.where(FormScript.enabled == 1)
|
||||
.limit(1)
|
||||
)
|
||||
|
||||
doc = query.run(as_dict=True)
|
||||
if doc:
|
||||
return doc[0].script
|
||||
return [d.script for d in doc] if len(doc) > 1 else doc[0].script
|
||||
else:
|
||||
return None
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user