diff options
| author | Bhumika (OpenERP) <sbh@tinyerp.com> | 2011-05-12 10:31:43 +0530 |
|---|---|---|
| committer | Bhumika (OpenERP) <sbh@tinyerp.com> | 2011-05-12 10:31:43 +0530 |
| commit | 4b6fa91c17681ced3ad18e73697fa9b69a65fc30 (patch) | |
| tree | 62d4f43573b221285bb42585157634414f3e5c41 /addons/document/document.py | |
| parent | a6fae8f8b5b1fb8dfd6b1ffb98edfa2e01688d09 (diff) | |
| parent | 12f87010029b2616145bd97cc037bbc27d86ed57 (diff) | |
[MERGE] Merge with lp:openobject-addons
bzr revid: sbh@tinyerp.com-20110512050143-5tbc55oop00ksr4u
Diffstat (limited to 'addons/document/document.py')
| -rw-r--r-- | addons/document/document.py | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/addons/document/document.py b/addons/document/document.py index 1a553b23ed1..90f57438ce8 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,7 +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("UPDATE ir_attachment SET file_size=length(db_datas) WHERE file_size = 0;") + cr.execute("ALTER TABLE ir_attachment ALTER parent_id SET NOT NULL") + return True def _get_filestore(self, cr): @@ -279,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): |
