patch: added patch to create default sidebar fields layout from customize form
This commit is contained in:
parent
a1eb3a6dd4
commit
bbe5fa2249
@ -6,4 +6,5 @@ crm.patches.v1_0.move_crm_note_data_to_fcrm_note
|
|||||||
[post_model_sync]
|
[post_model_sync]
|
||||||
# Patches added in this section will be executed after doctypes are migrated
|
# 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_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
|
||||||
63
crm/patches/v1_0/create_default_sidebar_fields_layout.py
Normal file
63
crm/patches/v1_0/create_default_sidebar_fields_layout.py
Normal 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
|
||||||
@ -583,9 +583,11 @@ const deal_contacts = createResource({
|
|||||||
cache: ['deal_contacts', props.dealId],
|
cache: ['deal_contacts', props.dealId],
|
||||||
auto: true,
|
auto: true,
|
||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
fieldsLayout.data.find(
|
let contactSection = fieldsLayout.data.find(
|
||||||
(section) => section.name == 'contacts_section',
|
(section) => section.name == 'contacts_section',
|
||||||
).contacts = data.map((contact) => {
|
)
|
||||||
|
if (!contactSection) return
|
||||||
|
contactSection.contacts = data.map((contact) => {
|
||||||
return {
|
return {
|
||||||
name: contact.name,
|
name: contact.name,
|
||||||
full_name: contact.full_name,
|
full_name: contact.full_name,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user