From f2c1755c6a2fc9813856e733cab0ff80cf8a4604 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 13 Nov 2013 17:29:52 +0530 Subject: [PATCH] [minor] [fix] create custom field if field exists in table --- core/doctype/custom_field/custom_field.py | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/core/doctype/custom_field/custom_field.py b/core/doctype/custom_field/custom_field.py index e0593e0e78..f11652e4a3 100644 --- a/core/doctype/custom_field/custom_field.py +++ b/core/doctype/custom_field/custom_field.py @@ -108,17 +108,17 @@ def get_fields_label(dt=None, form=1): def create_custom_field_if_values_exist(doctype, df): df = webnotes._dict(df) - if webnotes.conn.sql("""select count(*) from `tab{doctype}` - where ifnull({fieldname},'')!=''""".format(doctype=doctype, fieldname=df.fieldname))[0][0]: - - webnotes.bean({ - "doctype":"Custom Field", - "dt": doctype, - "permlevel": df.permlevel or 0, - "label": df.label, - "fieldname": df.fieldname, - "fieldtype": df.fieldtype, - "options": df.options, - "insert_after": df.insert_after - }).insert() + if df.fieldname in webnotes.conn.get_table_columns(doctype) and \ + webnotes.conn.sql("""select count(*) from `tab{doctype}` + where ifnull({fieldname},'')!=''""".format(doctype=doctype, fieldname=df.fieldname))[0][0]: + webnotes.bean({ + "doctype":"Custom Field", + "dt": doctype, + "permlevel": df.permlevel or 0, + "label": df.label, + "fieldname": df.fieldname, + "fieldtype": df.fieldtype, + "options": df.options, + "insert_after": df.insert_after + }).insert()