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):
|
class CRMFormScript(Document):
|
||||||
def validate(self):
|
pass
|
||||||
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,
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_form_script(dt, view="Form"):
|
def get_form_script(dt, view="Form"):
|
||||||
"""Returns the form script for the given doctype"""
|
"""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.dt == dt)
|
||||||
.where(FormScript.view == view)
|
.where(FormScript.view == view)
|
||||||
.where(FormScript.enabled == 1)
|
.where(FormScript.enabled == 1)
|
||||||
.limit(1)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
doc = query.run(as_dict=True)
|
doc = query.run(as_dict=True)
|
||||||
if doc:
|
if doc:
|
||||||
return doc[0].script
|
return [d.script for d in doc] if len(doc) > 1 else doc[0].script
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user