[patches] [file data] fixes in file data patch
diff --git a/patches/april_2013/p05_update_file_data.py b/patches/april_2013/p05_update_file_data.py
index 1ff48fa..d387741 100644
--- a/patches/april_2013/p05_update_file_data.py
+++ b/patches/april_2013/p05_update_file_data.py
@@ -53,10 +53,17 @@
exists = False
if exists:
- webnotes.conn.sql("""update `tabFile Data`
- set attached_to_doctype=%s, attached_to_name=%s
- where name=%s""", (doctype, doc.name, fileid))
-
+ if webnotes.conn.exists("File Data", fileid):
+ fd = webnotes.bean("File Data", fileid)
+ if not (fd.doc.attached_to_doctype and fd.doc.attached_to_name):
+ fd.doc.attached_to_doctype = doctype
+ fd.doc.attached_to_name = doc.name
+ fd.save()
+ else:
+ fd = webnotes.bean("File Data", copy=fd.doclist)
+ fd.doc.attached_to_doctype = doctype
+ fd.doc.attached_to_name = doc.name
+ fd.insert()
else:
webnotes.conn.sql("""delete from `tabFile Data` where name=%s""",
- fileid)
\ No newline at end of file
+ fileid)
\ No newline at end of file