[patch] [file data] fix

This commit is contained in:
Anand Doshi 2013-04-29 15:27:57 +05:30
parent 28eae6e9ff
commit fe5fb33cc2

View File

@ -56,20 +56,20 @@ def update_for_doc(doctype, doc):
if exists: if exists:
if webnotes.conn.exists("File Data", fileid): if webnotes.conn.exists("File Data", fileid):
fd = webnotes.bean("File Data", fileid) try:
if not (fd.doc.attached_to_doctype and fd.doc.attached_to_name): fd = webnotes.bean("File Data", fileid)
fd.doc.attached_to_doctype = doctype if not (fd.doc.attached_to_doctype and fd.doc.attached_to_name):
fd.doc.attached_to_name = doc.name fd.doc.attached_to_doctype = doctype
fd.save() fd.doc.attached_to_name = doc.name
else: fd.save()
try: else:
fd = webnotes.bean("File Data", copy=fd.doclist) fd = webnotes.bean("File Data", copy=fd.doclist)
fd.doc.attached_to_doctype = doctype fd.doc.attached_to_doctype = doctype
fd.doc.attached_to_name = doc.name fd.doc.attached_to_name = doc.name
fd.doc.name = None fd.doc.name = None
fd.insert() fd.insert()
except webnotes.DuplicateEntryError: except webnotes.DuplicateEntryError:
pass pass
else: else:
webnotes.conn.sql("""delete from `tabFile Data` where name=%s""", webnotes.conn.sql("""delete from `tabFile Data` where name=%s""",
fileid) fileid)