X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=addons%2Fdocument%2Fdocument.py;h=69e123b87ebc7aa7a41d1f75f5342f07039e5ff2;hb=bcf4574d1e6a1da9cad75e0695e8c33e6df8e2ea;hp=50769ea0fda0e028b4d863caaa3c890761ffc5a2;hpb=8a532eb87129f86c17edb35ec914b4452c3cf808;p=odoo%2Fodoo.git diff --git a/addons/document/document.py b/addons/document/document.py index 50769ea..69e123b 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -64,15 +64,9 @@ class document_file(osv.osv): "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 @@ -123,7 +117,7 @@ class document_file(osv.osv): # 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), @@ -290,10 +284,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):