From ec6de13451065a862cb80ee8258f1aa33c6f946a Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Fri, 7 Jun 2024 19:53:46 +0530 Subject: [PATCH] feat: get quick entry fields api --- crm/api/doc.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/crm/api/doc.py b/crm/api/doc.py index fae49446..f8e20b85 100644 --- a/crm/api/doc.py +++ b/crm/api/doc.py @@ -1,4 +1,5 @@ import frappe +import json from frappe import _ from frappe.model.document import get_controller from frappe.model import no_value_fields @@ -156,6 +157,43 @@ def get_group_by_fields(doctype: str): return fields +@frappe.whitelist() +def get_quick_entry_fields(doctype: str): + sections = [] + if frappe.db.exists("CRM Fields Layout", {"dt": doctype, "type": "Quick Entry"}): + layout = frappe.get_doc("CRM Fields Layout", {"dt": doctype, "type": "Quick Entry"}) + else: + return [] + + if layout.layout: + sections = json.loads(layout.layout) + + allowed_fields = [] + for section in sections: + allowed_fields.extend(section.get("fields")) + + fields = frappe.get_meta(doctype).fields + fields = [field for field in fields if field.fieldname in allowed_fields] + + for section in sections: + for field in section.get("fields"): + field = next((f for f in fields if f.fieldname == field), None) + if field: + if field.fieldtype == "Select": + field.options = field.options.split("\n") + field.options = [{"label": _(option), "value": option} for option in field.options] + field.options.insert(0, {"label": "", "value": ""}) + field = { + "label": _(field.label), + "name": field.fieldname, + "type": field.fieldtype, + "options": field.options, + "mandatory": field.reqd, + } + section["fields"][section.get("fields").index(field["name"])] = field + + return sections or [] + def get_fields_meta(DocField, doctype, allowed_fieldtypes, restricted_fields): parent = "parent" if DocField._table_name == "tabDocField" else "dt" return (