custom fields creation patch - not to be executed automatically

This commit is contained in:
Anand Doshi
2012-04-11 17:49:21 +05:30
parent ece64fa908
commit e68fe505b9
6 changed files with 153 additions and 32 deletions

View File

@@ -6,9 +6,35 @@ def execute():
* Remove docfield property setters if fieldname doesn't exist
* Remove prev_field properties if value fieldname doesn't exist
"""
change_property_setter_fieldnames()
clean_doctype_properties()
clean_docfield_properties()
def change_property_setter_fieldnames():
import webnotes.model.sync
webnotes.model.sync.sync('core', 'property_setter')
docfield_list = webnotes.conn.sql("""\
SELECT name, fieldname FROM `tabDocField`""", as_list=1)
custom_field_list = webnotes.conn.sql("""\
SELECT name, fieldname FROM `tabCustom Field`""", as_list=1)
field_list = docfield_list + custom_field_list
property_setter_list = webnotes.conn.sql("""\
SELECT name, doc_name, value, property
FROM `tabProperty Setter`
WHERE doctype_or_field='DocField'""")
field_dict = dict(field_list)
for name, doc_name, value, prop in property_setter_list:
if doc_name in field_dict:
webnotes.conn.sql("""\
UPDATE `tabProperty Setter`
SET field_name = %s
WHERE name = %s""", (field_dict.get(doc_name), name))
if value in field_dict and prop=='previous_field':
webnotes.conn.sql("""\
UPDATE `tabProperty Setter`
SET value = %s
WHERE name = %s""", (field_dict.get(value), name))
def clean_doctype_properties():
desc = webnotes.conn.sql("DESC `tabDocType`", as_dict=1)
property_list = '", "'.join([d.get('Field') for d in desc])