From 2ffd729ece17c0c6ec6c23a1568eece618650b33 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Sun, 29 Dec 2024 22:03:14 +0530 Subject: [PATCH] fix: load default layout if not exist --- .../crm_fields_layout/crm_fields_layout.py | 28 +++++++++++++++++-- .../src/components/Controls/GridRowModal.vue | 21 ++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/crm/fcrm/doctype/crm_fields_layout/crm_fields_layout.py b/crm/fcrm/doctype/crm_fields_layout/crm_fields_layout.py index 0d06ca43..54797ba2 100644 --- a/crm/fcrm/doctype/crm_fields_layout/crm_fields_layout.py +++ b/crm/fcrm/doctype/crm_fields_layout/crm_fields_layout.py @@ -15,14 +15,17 @@ class CRMFieldsLayout(Document): @frappe.whitelist() def get_fields_layout(doctype: str, type: str): tabs = [] + layout = None + if frappe.db.exists("CRM Fields Layout", {"dt": doctype, "type": type}): layout = frappe.get_doc("CRM Fields Layout", {"dt": doctype, "type": type}) - else: - return [] - if layout.layout: + if layout and layout.layout: tabs = json.loads(layout.layout) + if not tabs: + tabs = get_default_layout(doctype) + has_tabs = tabs[0].get("sections") if tabs and tabs[0] else False if not has_tabs: @@ -78,3 +81,22 @@ def save_fields_layout(doctype: str, type: str, layout: str): doc.save(ignore_permissions=True) return doc.layout + + +def get_default_layout(doctype: str): + fields = frappe.get_meta(doctype).fields + fields = [ + { + "label": _(field.label), + "name": field.fieldname, + "type": field.fieldtype, + "options": field.options, + "mandatory": field.reqd, + "placeholder": field.get("placeholder"), + "filters": field.get("link_filters"), + } + for field in fields + if field.fieldtype not in ["Section Break", "Column Break"] + ] + + return [{"no_tabs": True, "sections": [{"hideLabel": True, "fields": fields}]}] diff --git a/frontend/src/components/Controls/GridRowModal.vue b/frontend/src/components/Controls/GridRowModal.vue index 69351f22..91ad60c0 100644 --- a/frontend/src/components/Controls/GridRowModal.vue +++ b/frontend/src/components/Controls/GridRowModal.vue @@ -33,6 +33,7 @@