Merge pull request #19430 from frappe/fix-auto-enable-in-list-view
This commit is contained in:
commit
d84f6f249d
2 changed files with 36 additions and 8 deletions
|
|
@ -195,10 +195,12 @@ class DocType(Document):
|
|||
|
||||
def set_default_in_list_view(self):
|
||||
"""Set default in-list-view for first 4 mandatory fields"""
|
||||
not_allowed_in_list_view = get_fields_not_allowed_in_list_view(self.meta)
|
||||
|
||||
if not [d.fieldname for d in self.fields if d.in_list_view]:
|
||||
cnt = 0
|
||||
for d in self.fields:
|
||||
if d.reqd and not d.hidden and not d.fieldtype in table_fields:
|
||||
if d.reqd and not d.hidden and not d.fieldtype in not_allowed_in_list_view:
|
||||
d.in_list_view = 1
|
||||
cnt += 1
|
||||
if cnt == 4:
|
||||
|
|
@ -1446,10 +1448,7 @@ def validate_fields(meta):
|
|||
fields = meta.get("fields")
|
||||
fieldname_list = [d.fieldname for d in fields]
|
||||
|
||||
not_allowed_in_list_view = list(copy.copy(no_value_fields))
|
||||
not_allowed_in_list_view.append("Attach Image")
|
||||
if meta.istable:
|
||||
not_allowed_in_list_view.remove("Button")
|
||||
not_allowed_in_list_view = get_fields_not_allowed_in_list_view(meta)
|
||||
|
||||
for d in fields:
|
||||
if not d.permlevel:
|
||||
|
|
@ -1490,6 +1489,14 @@ def validate_fields(meta):
|
|||
check_image_field(meta)
|
||||
|
||||
|
||||
def get_fields_not_allowed_in_list_view(meta) -> list[str]:
|
||||
not_allowed_in_list_view = list(copy.copy(no_value_fields))
|
||||
not_allowed_in_list_view.append("Attach Image")
|
||||
if meta.istable:
|
||||
not_allowed_in_list_view.remove("Button")
|
||||
return not_allowed_in_list_view
|
||||
|
||||
|
||||
def validate_permissions_for_doctype(doctype, for_remove=False, alert=False):
|
||||
"""Validates if permissions are set correctly."""
|
||||
doctype = frappe.get_doc("DocType", doctype)
|
||||
|
|
|
|||
|
|
@ -722,6 +722,28 @@ class TestDocType(FrappeTestCase):
|
|||
self.assertEqual(frappe.get_meta(doctype).get_field(field).default, "DELETETHIS")
|
||||
frappe.delete_doc("DocType", doctype)
|
||||
|
||||
def test_not_in_list_view_for_not_allowed_mandatory_field(self):
|
||||
doctype = new_doctype(
|
||||
fields=[
|
||||
{
|
||||
"fieldname": "cover_image",
|
||||
"fieldtype": "Attach Image",
|
||||
"label": "Cover Image",
|
||||
"reqd": 1, # mandatory
|
||||
},
|
||||
{
|
||||
"fieldname": "book_name",
|
||||
"fieldtype": "Data",
|
||||
"label": "Book Name",
|
||||
"reqd": 1, # mandatory
|
||||
},
|
||||
],
|
||||
).insert()
|
||||
|
||||
self.assertFalse(doctype.fields[0].in_list_view)
|
||||
self.assertTrue(doctype.fields[1].in_list_view)
|
||||
frappe.delete_doc("DocType", doctype.name)
|
||||
|
||||
|
||||
def new_doctype(
|
||||
name: str | None = None,
|
||||
|
|
@ -759,8 +781,7 @@ def new_doctype(
|
|||
}
|
||||
)
|
||||
|
||||
if fields:
|
||||
for f in fields:
|
||||
doc.append("fields", f)
|
||||
if fields and len(fields) > 0:
|
||||
doc.set("fields", fields)
|
||||
|
||||
return doc
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue