blob: 52cf6b7f821380b4619d16fb2117ae7a9b64b111 [file] [log] [blame]
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05301# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
2# License: GNU General Public License v3. See license.txt
3
Anand Doshia30fbd02012-03-27 19:31:38 +05304# do not run this patch
Anand Doshi486f9df2012-07-19 13:40:31 +05305from __future__ import unicode_literals
Anand Doshia30fbd02012-03-27 19:31:38 +05306def execute():
7 import webnotes
8 import webnotes.modules
9 forbidden = ['%', "'", '"', '#', '*', '?', '`', '(', ')', '<', '>', '-',
10 '\\', '/', '.', '&', '!', '@', '$', '^', '+']
11 doctype_list = webnotes.conn.sql("SELECT name, module FROM `tabDocType`")
12 for doctype, module in doctype_list:
13 docfield_list = webnotes.conn.sql("""\
14 SELECT name, label, fieldtype FROM `tabDocField`
15 WHERE parent = %s AND IFNULL(fieldname, '') = ''""", doctype)
16 field_type_count = {}
17 count = 0
18 for name, label, fieldtype in docfield_list:
19 fieldname = None
20 if label:
21 temp_label = label
22 if len(temp_label)==1:
23 temp_label = fieldtype + temp_label
24
25 fieldname = temp_label.lower().replace(' ', '_')
26 if "<" in fieldname:
27 count = field_type_count.setdefault(fieldtype, 0)
28 fieldname = fieldtype.lower().replace(' ', '_') + str(count)
29 field_type_count[fieldtype] = count + 1
30 elif fieldtype:
31 count = field_type_count.setdefault(fieldtype, 0)
32 fieldname = fieldtype.lower().replace(' ', '_') + str(count)
33 field_type_count[fieldtype] = count + 1
34
35 if fieldname:
36 for f in forbidden: fieldname = fieldname.replace(f, '')
37 fieldname = fieldname.replace('__', '_')
38 if fieldname.endswith('_'):
39 fieldname = fieldname[:-1]
40 if fieldname.startswith('_'):
41 fieldname = fieldname[1:]
42 #print fieldname
43 webnotes.conn.sql("""\
44 UPDATE `tabDocField` SET fieldname = %s
45 WHERE name = %s""", (fieldname, name))
46 webnotes.modules.export_doc('DocType', doctype)