From 091d78558664543f38c0697a5b06886f0b002bcf Mon Sep 17 00:00:00 2001 From: "Anup (OpenERP)" Date: Wed, 30 Mar 2011 12:30:53 +0530 Subject: [FIX] document : File Content remained empty for old attachments fixed.(Support Case 4586) bzr revid: ach@tinyerp.com-20110330070053-p63h44msfy9rpaca --- addons/document/document.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 1a553b23ed1..822b9b7a4c2 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -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 -- cgit v1.2.3 From b11a71fd8751bc4fb33faa1f95f7915e230b86ab Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Thu, 7 Apr 2011 13:41:45 +0200 Subject: [MERGE] improvement project-issue bzr revid: tfr@openerp.com-20110407114145-xvr27pjquxwk9ff0 --- addons/document/document.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 1a553b23ed1..27a6c3d3c19 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -279,10 +279,22 @@ class document_file(osv.osv): else: if vals.get('file_size'): del vals['file_size'] - if not self._check_duplication(cr, uid, vals): - raise osv.except_osv(_('ValidateError'), _('File name must be unique!')) - result = super(document_file, self).create(cr, uid, vals, context) - cr.commit() # ? + result = self._check_duplication(cr, uid, vals) + if not result: + domain = [ + ('res_id', '=', vals['res_id']), + ('res_model', '=', vals['res_model']), + ('datas_fname', '=', vals['datas_fname']), + ] + attach_ids = self.search(cr, uid, domain, context=context) + super(document_file, self).write(cr, uid, attach_ids, + {'datas' : vals['datas']}, + context=context) + result = attach_ids[0] + else: + #raise osv.except_osv(_('ValidateError'), _('File name must be unique!')) + result = super(document_file, self).create(cr, uid, vals, context) + cr.commit() # ? return result def __get_partner_id(self, cr, uid, res_model, res_id, context=None): -- cgit v1.2.3