chore: moved fields layout related code to crm_fields_layout.py
This commit is contained in:
parent
bbe5fa2249
commit
6dbe3d2d53
@ -157,62 +157,6 @@ def get_group_by_fields(doctype: str):
|
|||||||
return fields
|
return fields
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def get_fields_layout(doctype: str, type: str):
|
|
||||||
sections = []
|
|
||||||
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:
|
|
||||||
sections = json.loads(layout.layout)
|
|
||||||
|
|
||||||
allowed_fields = []
|
|
||||||
for section in sections:
|
|
||||||
if not section.get("fields"):
|
|
||||||
continue
|
|
||||||
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") if section.get("fields") else []:
|
|
||||||
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 []
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def save_fields_layout(doctype: str, type: str, layout: str):
|
|
||||||
if frappe.db.exists("CRM Fields Layout", {"dt": doctype, "type": type}):
|
|
||||||
doc = frappe.get_doc("CRM Fields Layout", {"dt": doctype, "type": type})
|
|
||||||
else:
|
|
||||||
doc = frappe.new_doc("CRM Fields Layout")
|
|
||||||
|
|
||||||
doc.update({
|
|
||||||
"dt": doctype,
|
|
||||||
"type": type,
|
|
||||||
"layout": layout,
|
|
||||||
})
|
|
||||||
doc.save(ignore_permissions=True)
|
|
||||||
|
|
||||||
return doc.layout
|
|
||||||
|
|
||||||
def get_doctype_fields_meta(DocField, doctype, allowed_fieldtypes, restricted_fields):
|
def get_doctype_fields_meta(DocField, doctype, allowed_fieldtypes, restricted_fields):
|
||||||
parent = "parent" if DocField._table_name == "tabDocField" else "dt"
|
parent = "parent" if DocField._table_name == "tabDocField" else "dt"
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -1,9 +1,67 @@
|
|||||||
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
|
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
# import frappe
|
import json
|
||||||
|
import frappe
|
||||||
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|
||||||
class CRMFieldsLayout(Document):
|
class CRMFieldsLayout(Document):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_fields_layout(doctype: str, type: str):
|
||||||
|
sections = []
|
||||||
|
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:
|
||||||
|
sections = json.loads(layout.layout)
|
||||||
|
|
||||||
|
allowed_fields = []
|
||||||
|
for section in sections:
|
||||||
|
if not section.get("fields"):
|
||||||
|
continue
|
||||||
|
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") if section.get("fields") else []:
|
||||||
|
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 []
|
||||||
|
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def save_fields_layout(doctype: str, type: str, layout: str):
|
||||||
|
if frappe.db.exists("CRM Fields Layout", {"dt": doctype, "type": type}):
|
||||||
|
doc = frappe.get_doc("CRM Fields Layout", {"dt": doctype, "type": type})
|
||||||
|
else:
|
||||||
|
doc = frappe.new_doc("CRM Fields Layout")
|
||||||
|
|
||||||
|
doc.update({
|
||||||
|
"dt": doctype,
|
||||||
|
"type": type,
|
||||||
|
"layout": layout,
|
||||||
|
})
|
||||||
|
doc.save(ignore_permissions=True)
|
||||||
|
|
||||||
|
return doc.layout
|
||||||
|
|||||||
@ -235,7 +235,7 @@ const detailFields = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const sections = createResource({
|
const sections = createResource({
|
||||||
url: 'crm.api.doc.get_fields_layout',
|
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_fields_layout',
|
||||||
cache: ['quickEntryFields', 'Contact'],
|
cache: ['quickEntryFields', 'Contact'],
|
||||||
params: { doctype: 'Contact', type: 'Quick Entry'},
|
params: { doctype: 'Contact', type: 'Quick Entry'},
|
||||||
auto: true,
|
auto: true,
|
||||||
|
|||||||
@ -77,7 +77,7 @@ const chooseExistingContact = ref(false)
|
|||||||
const chooseExistingOrganization = ref(false)
|
const chooseExistingOrganization = ref(false)
|
||||||
|
|
||||||
const sections = createResource({
|
const sections = createResource({
|
||||||
url: 'crm.api.doc.get_fields_layout',
|
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_fields_layout',
|
||||||
cache: ['quickEntryFields', 'CRM Deal'],
|
cache: ['quickEntryFields', 'CRM Deal'],
|
||||||
params: { doctype: 'CRM Deal', type: 'Quick Entry'},
|
params: { doctype: 'CRM Deal', type: 'Quick Entry'},
|
||||||
auto: true,
|
auto: true,
|
||||||
|
|||||||
@ -40,7 +40,7 @@ const error = ref(null)
|
|||||||
const isLeadCreating = ref(false)
|
const isLeadCreating = ref(false)
|
||||||
|
|
||||||
const sections = createResource({
|
const sections = createResource({
|
||||||
url: 'crm.api.doc.get_fields_layout',
|
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_fields_layout',
|
||||||
cache: ['quickEntryFields', 'CRM Lead'],
|
cache: ['quickEntryFields', 'CRM Lead'],
|
||||||
params: { doctype: 'CRM Lead', type: 'Quick Entry' },
|
params: { doctype: 'CRM Lead', type: 'Quick Entry' },
|
||||||
auto: true,
|
auto: true,
|
||||||
|
|||||||
@ -225,7 +225,7 @@ const fields = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const sections = createResource({
|
const sections = createResource({
|
||||||
url: 'crm.api.doc.get_fields_layout',
|
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_fields_layout',
|
||||||
cache: ['quickEntryFields', 'CRM Organization'],
|
cache: ['quickEntryFields', 'CRM Organization'],
|
||||||
params: { doctype: 'CRM Organization', type: 'Quick Entry'},
|
params: { doctype: 'CRM Organization', type: 'Quick Entry'},
|
||||||
auto: true,
|
auto: true,
|
||||||
|
|||||||
@ -56,7 +56,7 @@ const doctype = ref('CRM Lead')
|
|||||||
const oldSections = ref([])
|
const oldSections = ref([])
|
||||||
|
|
||||||
const sections = createResource({
|
const sections = createResource({
|
||||||
url: 'crm.api.doc.get_fields_layout',
|
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_fields_layout',
|
||||||
cache: ['sidebar-sections', doctype.value],
|
cache: ['sidebar-sections', doctype.value],
|
||||||
params: { doctype: doctype.value, type: 'Side Panel' },
|
params: { doctype: doctype.value, type: 'Side Panel' },
|
||||||
auto: true,
|
auto: true,
|
||||||
@ -78,7 +78,7 @@ function saveChanges() {
|
|||||||
section.fields = section.fields.map((field) => field.fieldname || field.name)
|
section.fields = section.fields.map((field) => field.fieldname || field.name)
|
||||||
})
|
})
|
||||||
loading.value = true
|
loading.value = true
|
||||||
call('crm.api.doc.save_fields_layout', {
|
call('crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.save_fields_layout', {
|
||||||
doctype: doctype.value,
|
doctype: doctype.value,
|
||||||
type: 'Side Panel',
|
type: 'Side Panel',
|
||||||
layout: JSON.stringify(_sections),
|
layout: JSON.stringify(_sections),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user