From 123f59dc89cf3858678ba8a71bfd72e9a3b9438b Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 29 Apr 2013 14:21:42 +0530 Subject: [PATCH] [patches] [file data] fixes in file data patch --- patches/april_2013/p05_update_file_data.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/patches/april_2013/p05_update_file_data.py b/patches/april_2013/p05_update_file_data.py index 1ff48fa60e8..d3877417e2b 100644 --- a/patches/april_2013/p05_update_file_data.py +++ b/patches/april_2013/p05_update_file_data.py @@ -53,10 +53,17 @@ def update_for_doc(doctype, doc): 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