From 9f63bfe3d8dcd416cb2c03e5af4beb22c3b4e702 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 30 Apr 2012 18:27:59 +0530 Subject: [PATCH 1/2] fixes in rename function --- py/webnotes/model/__init__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/py/webnotes/model/__init__.py b/py/webnotes/model/__init__.py index abe6f4227c..a05f4fd259 100644 --- a/py/webnotes/model/__init__.py +++ b/py/webnotes/model/__init__.py @@ -158,16 +158,16 @@ def rename(dt, old, new, is_doctype = 0): # get links (link / select) ll = get_link_fields(dt) update_link_fld_values(ll, old, new) - - # update options and values where select options contains old dt - select_flds = sql("select parent, fieldname from `tabDocField` where parent not like 'old%%' and options like '%%%s%%' and options not like 'link:%%' and fieldtype = 'Select' and parent != '%s'" % (old, new)) - update_link_fld_values(select_flds, old, new) - - sql("update `tabDocField` set options = replace(options, '%s', '%s') where options like '%%%s%%'" % (old, new, old)) # doctype - if is_doctype: + if is_doctype: + # update options and values where select options contains old dt + select_flds = sql("select parent, fieldname from `tabDocField` where parent not like 'old%%' and options like '%%%s%%' and options not like 'link:%%' and fieldtype = 'Select' and parent != '%s'" % (old, new)) + update_link_fld_values(select_flds, old, new) + + sql("update `tabDocField` set options = replace(options, '%s', '%s') where options like '%%%s%%'" % (old, new, old)) + if not is_single_dt(old): sql("RENAME TABLE `tab%s` TO `tab%s`" % (old, new)) else: From d9bb3ef19781686122fda2f9a48b1c65872ab77b Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 1 May 2012 16:48:00 +0530 Subject: [PATCH 2/2] fix in rename function --- py/webnotes/model/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py/webnotes/model/__init__.py b/py/webnotes/model/__init__.py index a05f4fd259..2eee64116f 100644 --- a/py/webnotes/model/__init__.py +++ b/py/webnotes/model/__init__.py @@ -163,10 +163,10 @@ def rename(dt, old, new, is_doctype = 0): # doctype if is_doctype: # update options and values where select options contains old dt - select_flds = sql("select parent, fieldname from `tabDocField` where parent not like 'old%%' and options like '%%%s%%' and options not like 'link:%%' and fieldtype = 'Select' and parent != '%s'" % (old, new)) + select_flds = sql("select parent, fieldname from `tabDocField` where parent not like 'old%%' and (options like '%%%s%%' or options like '%%%s%%') and options not like 'link:%%' and fieldtype = 'Select' and parent != '%s'" % ('\n' + old, old + '\n', new)) update_link_fld_values(select_flds, old, new) - sql("update `tabDocField` set options = replace(options, '%s', '%s') where options like '%%%s%%'" % (old, new, old)) + sql("update `tabDocField` set options = replace(options, '%s', '%s') where (options like '%%%s%%' or options like '%%%s%%')" % (old, new, '\n' + old, old + '\n')) if not is_single_dt(old): sql("RENAME TABLE `tab%s` TO `tab%s`" % (old, new))