"SET parent_id = %s, db_datas = decode(encode(db_datas,'escape'), 'base64') " \
"WHERE parent_id IS NULL", (parent_id,))
- cr.execute("ALTER TABLE ir_attachment ALTER parent_id SET NOT NULL")
-
- #Proceeding to update the filesize of the corresponsing attachment
- cr.execute('SELECT id, db_datas FROM ir_attachment WHERE file_size=0 AND db_datas IS NOT NULL')
- old_attachments = cr.dictfetchall()
+ cr.execute("UPDATE ir_attachment SET file_size=length(db_datas) WHERE file_size = 0;")
- for attachment in old_attachments:
- f_size = len(attachment['db_datas'])
- 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
# If ir.attachment contained any data before document is installed, preserve
# the data, don't drop the column!
'db_datas': fields.binary('Data', oldname='datas'),
- 'datas': fields.function(_data_get, method=True, fnct_inv=_data_set, string='File Content', type="binary", nodrop=True),
+ 'datas': fields.function(_data_get, fnct_inv=_data_set, string='File Content', type="binary", nodrop=True),
# Fields of document:
'user_id': fields.many2one('res.users', 'Owner', select=1),
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):