fix: load default layout if not exist
This commit is contained in:
parent
2be808b511
commit
2ffd729ece
@ -15,14 +15,17 @@ class CRMFieldsLayout(Document):
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_fields_layout(doctype: str, type: str):
|
def get_fields_layout(doctype: str, type: str):
|
||||||
tabs = []
|
tabs = []
|
||||||
|
layout = None
|
||||||
|
|
||||||
if frappe.db.exists("CRM Fields Layout", {"dt": doctype, "type": type}):
|
if frappe.db.exists("CRM Fields Layout", {"dt": doctype, "type": type}):
|
||||||
layout = frappe.get_doc("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)
|
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
|
has_tabs = tabs[0].get("sections") if tabs and tabs[0] else False
|
||||||
|
|
||||||
if not has_tabs:
|
if not has_tabs:
|
||||||
@ -78,3 +81,22 @@ def save_fields_layout(doctype: str, type: str, layout: str):
|
|||||||
doc.save(ignore_permissions=True)
|
doc.save(ignore_permissions=True)
|
||||||
|
|
||||||
return doc.layout
|
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}]}]
|
||||||
|
|||||||
@ -33,6 +33,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import EditIcon from '@/components/Icons/EditIcon.vue'
|
import EditIcon from '@/components/Icons/EditIcon.vue'
|
||||||
import FieldLayout from '@/components/FieldLayout.vue'
|
import FieldLayout from '@/components/FieldLayout.vue'
|
||||||
|
import { getMeta } from '@/stores/meta'
|
||||||
import { usersStore } from '@/stores/users'
|
import { usersStore } from '@/stores/users'
|
||||||
import { createResource } from 'frappe-ui'
|
import { createResource } from 'frappe-ui'
|
||||||
import { nextTick } from 'vue'
|
import { nextTick } from 'vue'
|
||||||
@ -43,6 +44,7 @@ const props = defineProps({
|
|||||||
doctype: String,
|
doctype: String,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const { getFields } = getMeta(props.doctype)
|
||||||
const { isManager } = usersStore()
|
const { isManager } = usersStore()
|
||||||
|
|
||||||
const show = defineModel()
|
const show = defineModel()
|
||||||
@ -53,6 +55,25 @@ const tabs = createResource({
|
|||||||
cache: ['GridRow', props.doctype],
|
cache: ['GridRow', props.doctype],
|
||||||
params: { doctype: props.doctype, type: 'Grid Row' },
|
params: { doctype: props.doctype, type: 'Grid Row' },
|
||||||
auto: true,
|
auto: true,
|
||||||
|
transform: (data) => {
|
||||||
|
if (data.length) return data
|
||||||
|
let fields = getFields()
|
||||||
|
if (!fields) return []
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
no_tabs: true,
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
hideLabel: true,
|
||||||
|
opened: true,
|
||||||
|
fields: fields.map((f) => {
|
||||||
|
return { ...f, name: f.fieldname, type: f.fieldtype }
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
function openGridRowFieldsModal() {
|
function openGridRowFieldsModal() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user