delete records in child table where parent is missing or parent is like
old_par%
diff --git a/erpnext/patches/june_2012/delete_old_parent_entries.py b/erpnext/patches/june_2012/delete_old_parent_entries.py
new file mode 100644
index 0000000..c74f609
--- /dev/null
+++ b/erpnext/patches/june_2012/delete_old_parent_entries.py
@@ -0,0 +1,17 @@
+def execute():
+ """delete entries of child table having parent like old_par%% or ''"""
+ import webnotes
+ res = webnotes.conn.sql("""\
+ select dt.name from `tabDocType` dt
+ where ifnull(dt.istable, 0)=1 and
+ exists (
+ select * from `tabDocField` df
+ where df.fieldtype='Table' and
+ df.options=dt.name
+ )""")
+ for r in res:
+ if r[0]:
+ webnotes.conn.sql("""\
+ delete from `tab%s`
+ where (ifnull(parent, '')='' or parent like "old_par%%") and
+ ifnull(parenttype, '')!=''""" % r[0])
\ No newline at end of file
diff --git a/erpnext/patches/patch_list.py b/erpnext/patches/patch_list.py
index 03c0f27..5e5f4c9 100644
--- a/erpnext/patches/patch_list.py
+++ b/erpnext/patches/patch_list.py
@@ -452,4 +452,9 @@
'patch_file': 'alter_tabsessions',
'description': "alter tabsessions to change user column definition"
},
+ {
+ 'patch_module': 'patches.june_2012',
+ 'patch_file': 'delete_old_parent_entries',
+ 'description': "delete entries of child table having parent like old_par%% or ''"
+ },
]
\ No newline at end of file