From b1ea3edcebd8dbabf96076f1304b1a38dcc24603 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Tue, 1 Jul 2025 16:05:08 +0530 Subject: [PATCH] fix: add mandatory fields in convert to deal modal if not added (cherry picked from commit 17fdbb05cedad890631465d1ad64fbc502dd00c9) --- .../crm_fields_layout/crm_fields_layout.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) 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 1fd85824..9274e857 100644 --- a/crm/fcrm/doctype/crm_fields_layout/crm_fields_layout.py +++ b/crm/fcrm/doctype/crm_fields_layout/crm_fields_layout.py @@ -47,6 +47,13 @@ def get_fields_layout(doctype: str, type: str, parent_doctype: str | None = None fields = frappe.get_meta(doctype).fields fields = [field for field in fields if field.fieldname in allowed_fields] + required_fields = [] + + if type == "Required Fields": + required_fields = [ + field for field in frappe.get_meta(doctype, False).fields if field.reqd and not field.default + ] + for tab in tabs: for section in tab.get("sections"): if section.get("columns"): @@ -60,6 +67,32 @@ def get_fields_layout(doctype: str, type: str, parent_doctype: str | None = None handle_perm_level_restrictions(field, doctype, parent_doctype) column["fields"][column.get("fields").index(field["fieldname"])] = field + # remove field from required_fields if it is already present + if ( + type == "Required Fields" + and field.reqd + and any(f.get("fieldname") == field.get("fieldname") for f in required_fields) + ): + required_fields = [ + f for f in required_fields if f.get("fieldname") != field.get("fieldname") + ] + + if type == "Required Fields" and required_fields and tabs: + tabs[-1].get("sections").append( + { + "label": "Required Fields", + "name": "required_fields_section_" + str(random_string(4)), + "opened": True, + "hideLabel": True, + "columns": [ + { + "name": "required_fields_column_" + str(random_string(4)), + "fields": [field.as_dict() for field in required_fields], + } + ], + } + ) + return tabs or []