[Fix] Don't allow user to change the select fieldtype to data from the customize form

This commit is contained in:
Rohit Waghchaure 2017-06-21 18:17:11 +05:30
parent 0879ecf326
commit 2c5e6c7d0f
2 changed files with 16 additions and 3 deletions

View file

@ -943,6 +943,7 @@ def make_property_setter(args, ignore_validate=False, validate_fields_for_doctyp
})
ps.flags.ignore_validate = ignore_validate
ps.flags.validate_fields_for_doctype = validate_fields_for_doctype
ps.validate_fieldtype_change()
ps.insert()
def import_doc(path, ignore_links=False, ignore_insert=False, insert=False):

View file

@ -3,9 +3,12 @@
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.model.document import Document
not_allowed_fieldtype_change = ['naming_series']
class PropertySetter(Document):
def autoname(self):
self.name = self.doc_type + "-" \
@ -13,6 +16,18 @@ class PropertySetter(Document):
+ self.property
def validate(self):
self.validate_fieldtype_change()
self.delete_property_setter()
# clear cache
frappe.clear_cache(doctype = self.doc_type)
def validate_fieldtype_change(self):
if self.field_name in not_allowed_fieldtype_change and \
self.property == 'fieldtype':
frappe.throw(_("Field type cannot be changed for {0}").format(self.field_name))
def delete_property_setter(self):
"""delete other property setters on this, if this is new"""
if self.get('__islocal'):
frappe.db.sql("""delete from `tabProperty Setter` where
@ -21,9 +36,6 @@ class PropertySetter(Document):
and ifnull(field_name,'') = ifnull(%(field_name)s, '')
and property = %(property)s""", self.get_valid_dict())
# clear cache
frappe.clear_cache(doctype = self.doc_type)
def get_property_list(self, dt):
return frappe.db.sql("""select fieldname, label, fieldtype
from tabDocField