Delete Property Setters for Custom Fields, and set them inside Custom Field
This commit is contained in:
parent
14bf711d04
commit
c43d58ac79
@ -2,34 +2,24 @@
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
import webnotes
|
||||
from webnotes.model.meta import get_field
|
||||
|
||||
def execute():
|
||||
webnotes.reload_doc("core", "doctype", "custom_field")
|
||||
|
||||
custom_fields = {}
|
||||
for cf in webnotes.conn.sql("""select dt, fieldname from `tabCustom Field`""", as_dict=1):
|
||||
custom_fields.setdefault(cf.dt, []).append(cf.fieldname)
|
||||
|
||||
cf_doclist = webnotes.get_doctype("Custom Field")
|
||||
|
||||
delete_list = []
|
||||
for ps in webnotes.conn.sql("""select * from `tabProperty Setter`""", as_dict=1):
|
||||
if ps.field_name in custom_fields.get(ps.doc_type, []):
|
||||
|
||||
if ps.property == "previous_field":
|
||||
property_name = "insert_after"
|
||||
for d in webnotes.conn.sql("""select cf.name as cf_name, ps.property,
|
||||
ps.value, ps.name as ps_name
|
||||
from `tabProperty Setter` ps, `tabCustom Field` cf
|
||||
where ps.doctype_or_field = 'DocField' and ps.property != 'previous_field'
|
||||
and ps.doc_type=cf.dt and ps.field_name=cf.fieldname""", as_dict=1):
|
||||
if cf_doclist.get_field(d.property):
|
||||
webnotes.conn.sql("""update `tabCustom Field`
|
||||
set `%s`=%s where name=%s""" % (d.property, '%s', '%s'), (d.value, d.cf_name))
|
||||
|
||||
field_meta = get_field(ps.doc_type, ps.value)
|
||||
property_value = field_meta.label if field_meta else ""
|
||||
else:
|
||||
property_name = ps.property
|
||||
property_value =ps.value
|
||||
delete_list.append(d.ps_name)
|
||||
|
||||
webnotes.conn.sql("""update `tabCustom Field`
|
||||
set %s=%s where dt=%s and fieldname=%s""" % (property_name, '%s', '%s', '%s'),
|
||||
(property_value, ps.doc_type, ps.field_name))
|
||||
|
||||
delete_list.append(ps.name)
|
||||
|
||||
if delete_list:
|
||||
webnotes.conn.sql("""delete from `tabProperty Setter` where name in (%s)""" %
|
||||
', '.join(['%s']*len(delete_list)), tuple(delete_list))
|
Loading…
x
Reference in New Issue
Block a user