fix(ux): validate max_attachment on doctype controller

This commit is contained in:
Ankush Menat 2021-11-30 12:18:52 +05:30
parent db101e5ec3
commit 2f6b57cc0a
2 changed files with 22 additions and 0 deletions

View file

@ -75,6 +75,7 @@ class DocType(Document):
self.make_repeatable()
self.validate_nestedset()
self.validate_website()
self.ensure_minimum_max_attachment_limit()
validate_links_table_fieldnames(self)
if not self.is_new():
@ -246,6 +247,22 @@ class DocType(Document):
# clear website cache
clear_cache()
def ensure_minimum_max_attachment_limit(self):
"""Ensure that max_attachments is *at least* bigger than number of attach fields."""
from frappe.model import attachment_fieldtypes
if not self.max_attachments:
return
total_attach_fields = len([d for d in self.fields if d.fieldtype in attachment_fieldtypes])
if total_attach_fields > self.max_attachments:
self.max_attachments = total_attach_fields
field_label = frappe.bold(self.meta.get_field("max_attachments").label)
frappe.msgprint(_("Number of attachment fields are more than {}, limit updated to {}.")
.format(field_label, total_attach_fields),
title=_("Insufficient attachment limit"), alert=True)
def change_modified_of_parent(self):
"""Change the timestamp of parent DocType if the current one is a child to clear caches."""
if frappe.flags.in_import:

View file

@ -38,6 +38,11 @@ data_fieldtypes = (
'Icon'
)
attachment_fieldtypes = (
'Attach',
'Attach Image',
)
no_value_fields = (
'Section Break',
'Column Break',