fix: load form_script when lead is loaded

This commit is contained in:
Shariq Ansari 2023-12-28 16:33:58 +05:30
parent dde6b45201
commit 7d7cadaad8
2 changed files with 20 additions and 1 deletions

View File

@ -26,3 +26,20 @@ class CRMFormScript(Document):
),
frappe.DuplicateEntryError,
)
def get_form_script(dt):
"""Returns the script for the given doctype"""
FormScript = frappe.qb.DocType("CRM Form Script")
query = (
frappe.qb.from_(FormScript)
.select("script")
.where(FormScript.dt == dt)
.where(FormScript.enabled == 1)
.limit(1)
)
doc = query.run(as_dict=True)
if doc:
return doc[0].script
else:
return None

View File

@ -2,6 +2,7 @@ import frappe
from frappe import _
from crm.api.doc import get_doctype_fields
from crm.fcrm.doctype.crm_form_script.crm_form_script import get_form_script
@frappe.whitelist()
def get_lead(name):
@ -16,4 +17,5 @@ def get_lead(name):
lead["doctype_fields"] = get_doctype_fields("CRM Lead")
lead["doctype"] = "CRM Lead"
return lead
lead["_form_script"] = get_form_script('CRM Lead')
return lead