[FIX] document : File Content remained empty for old attachments fixed.(Support Case 4586)

bzr revid: ach@tinyerp.com-20110330070053-p63h44msfy9rpaca
This commit is contained in:
Anup (OpenERP) 2011-03-30 12:30:53 +05:30
parent 7f23337493
commit 091d785586
1 changed files with 6 additions and 0 deletions

View File

@ -49,6 +49,7 @@ class document_file(osv.osv):
It also establishes the parent_id NOT NULL constraint that ir.attachment
should have had (but would have failed if plain attachments contained null
values).
It also updates the File Size for the previously created attachments.
"""
parent_id = self.pool.get('document.directory')._get_root_directory(cr,uid)
@ -62,6 +63,11 @@ class document_file(osv.osv):
cr.execute("UPDATE ir_attachment " \
"SET parent_id = %s, db_datas = decode(encode(db_datas,'escape'), 'base64') " \
"WHERE parent_id IS NULL", (parent_id,))
cr.execute('SELECT id, db_datas FROM ir_attachment WHERE file_size=0')
old_attachments = cr.dictfetchall()
for attachment in old_attachments:
f_size = attachment['db_datas'].__len__()
cr.execute('UPDATE ir_attachment SET file_size=%s WHERE id=%s',(f_size,attachment['id']))
cr.execute("ALTER TABLE ir_attachment ALTER parent_id SET NOT NULL")
return True