1
0
forked from test/crm

patch: added patch to create default sidebar fields layout from customize form

This commit is contained in:
Shariq Ansari 2024-06-15 17:52:53 +05:30
parent a1eb3a6dd4
commit bbe5fa2249
3 changed files with 69 additions and 3 deletions

View File

@ -6,4 +6,5 @@ crm.patches.v1_0.move_crm_note_data_to_fcrm_note
[post_model_sync]
# Patches added in this section will be executed after doctypes are migrated
crm.patches.v1_0.create_email_template_custom_fields
crm.patches.v1_0.create_default_fields_layout
crm.patches.v1_0.create_default_fields_layout
crm.patches.v1_0.create_default_sidebar_fields_layout

View File

@ -0,0 +1,63 @@
import json
import frappe
def execute():
if not frappe.db.exists("CRM Fields Layout", {"dt": "CRM Lead", "type": "Side Panel"}):
create_doctype_fields_layout("CRM Lead")
if not frappe.db.exists("CRM Fields Layout", {"dt": "CRM Deal", "type": "Side Panel"}):
create_doctype_fields_layout("CRM Deal")
def create_doctype_fields_layout(doctype):
not_allowed_fieldtypes = [
"Section Break",
"Column Break",
]
fields = frappe.get_meta(doctype).fields
fields = [field for field in fields if field.fieldtype not in not_allowed_fieldtypes]
sections = {}
section_fields = []
last_section = None
for field in fields:
if field.fieldtype == "Tab Break" and last_section:
sections[last_section]["fields"] = section_fields
last_section = None
if field.read_only:
section_fields = []
continue
if field.fieldtype == "Tab Break":
if field.read_only:
section_fields = []
continue
section_fields = []
last_section = field.fieldname
sections[field.fieldname] = {
"label": field.label,
"name": field.fieldname,
"opened": True,
"fields": [],
}
if field.fieldname == "contacts_tab":
sections[field.fieldname]["editable"] = False
sections[field.fieldname]["contacts"] = []
else:
section_fields.append(field.fieldname)
section_fields = []
for section in sections:
if section == "contacts_tab":
sections[section]["name"] = "contacts_section"
sections[section].pop("fields", None)
section_fields.append(sections[section])
frappe.get_doc({
"doctype": "CRM Fields Layout",
"dt": doctype,
"type": "Side Panel",
"layout": json.dumps(section_fields),
}).insert(ignore_permissions=True)
return section_fields

View File

@ -583,9 +583,11 @@ const deal_contacts = createResource({
cache: ['deal_contacts', props.dealId],
auto: true,
onSuccess: (data) => {
fieldsLayout.data.find(
let contactSection = fieldsLayout.data.find(
(section) => section.name == 'contacts_section',
).contacts = data.map((contact) => {
)
if (!contactSection) return
contactSection.contacts = data.map((contact) => {
return {
name: contact.name,
full_name: contact.full_name,