summaryrefslogtreecommitdiff
path: root/addons/document/document.py
diff options
context:
space:
mode:
authorAntony Lesuisse <al@openerp.com>2012-12-16 20:09:50 +0100
committerAntony Lesuisse <al@openerp.com>2012-12-16 20:09:50 +0100
commitc90a1492d67fdfb63a3747489475362d0bd923d7 (patch)
treed05930660e4c3f7029cf290da4167377ef3e92a7 /addons/document/document.py
parent9c8aa2cb967a0ffd3d468604672e4ee2020fc558 (diff)
parent9a191f7f1717f5a0ae6c97b7a0ced0efbd0c17bf (diff)
[MERGE] trunk
bzr revid: al@openerp.com-20121216190950-n0sqzfsfyrlnlxoh
Diffstat (limited to 'addons/document/document.py')
-rw-r--r--addons/document/document.py65
1 files changed, 17 insertions, 48 deletions
diff --git a/addons/document/document.py b/addons/document/document.py
index 92ece063a47..37a0219d143 100644
--- a/addons/document/document.py
+++ b/addons/document/document.py
@@ -23,18 +23,20 @@ import base64
from osv import osv, fields
import os
-# from psycopg2 import Binary
+#from psycopg2 import Binary
#from tools import config
import tools
from tools.translate import _
import nodes
import logging
+_logger = logging.getLogger(__name__)
+
DMS_ROOT_PATH = tools.config.get('document_path', os.path.join(tools.config['root_path'], 'filestore'))
class document_file(osv.osv):
_inherit = 'ir.attachment'
- _rec_name = 'datas_fname'
+ _rec_name = 'name'
def _attach_parent_id(self, cr, uid, ids=None, context=None):
"""Migrate ir.attachments to the document module.
@@ -54,11 +56,11 @@ class document_file(osv.osv):
parent_id = self.pool.get('document.directory')._get_root_directory(cr,uid)
if not parent_id:
- logging.getLogger('document').warning("at _attach_parent_id(), still not able to set the parent!")
+ _logger.warning("at _attach_parent_id(), still not able to set the parent!")
return False
if ids is not None:
- raise NotImplementedError("Ids is just there by convention! Don't use it yet, please.")
+ raise NotImplementedError("Ids are just there by convention, please do not use it.")
cr.execute("UPDATE ir_attachment " \
"SET parent_id = %s, db_datas = decode(encode(db_datas,'escape'), 'base64') " \
@@ -140,35 +142,18 @@ class document_file(osv.osv):
_defaults = {
'user_id': lambda self, cr, uid, ctx:uid,
+ 'parent_id': __get_def_directory,
'file_size': lambda self, cr, uid, ctx:0,
- 'parent_id': __get_def_directory
}
_sql_constraints = [
# filename_uniq is not possible in pure SQL
]
- def _check_duplication(self, cr, uid, vals, ids=[], op='create'):
- name = vals.get('name', False)
- parent_id = vals.get('parent_id', False)
- res_model = vals.get('res_model', False)
- res_id = vals.get('res_id', 0)
- if op == 'write':
- for file in self.browse(cr, uid, ids): # FIXME fields_only
- if not name:
- name = file.name
- if not parent_id:
- parent_id = file.parent_id and file.parent_id.id or False
- if not res_model:
- res_model = file.res_model and file.res_model or False
- if not res_id:
- res_id = file.res_id and file.res_id or 0
- res = self.search(cr, uid, [('id', '<>', file.id), ('name', '=', name), ('parent_id', '=', parent_id), ('res_model', '=', res_model), ('res_id', '=', res_id)])
- if len(res):
- return False
- if op == 'create':
- res = self.search(cr, uid, [('name', '=', name), ('parent_id', '=', parent_id), ('res_id', '=', res_id), ('res_model', '=', res_model)])
- if len(res):
- return False
- return True
+
+ def onchange_file(self, cr, uid, ids, datas_fname=False, context=None):
+ res = {'value':{}}
+ if datas_fname:
+ res['value'].update({'name': datas_fname})
+ return res
def check(self, cr, uid, ids, mode, context=None, values=None):
"""Check access wrt. res_model, relax the rule of ir.attachment parent
@@ -206,7 +191,7 @@ class document_file(osv.osv):
default = {}
if 'name' not in default:
name = self.read(cr, uid, [id], ['name'])[0]['name']
- default.update({'name': name + " " + _("(copy)")})
+ default.update(name=_("%s (copy)") % (name))
return super(document_file, self).copy(cr, uid, id, default, context=context)
def write(self, cr, uid, ids, vals, context=None):
@@ -216,8 +201,6 @@ class document_file(osv.osv):
res = self.search(cr, uid, [('id', 'in', ids)])
if not len(res):
return False
- if not self._check_duplication(cr, uid, vals, ids, 'write'):
- raise osv.except_osv(_('ValidateError'), _('File name must be unique!'))
# if nodes call this write(), they must skip the code below
from_node = context and context.get('__from_node', False)
@@ -283,22 +266,8 @@ class document_file(osv.osv):
else:
if vals.get('file_size'):
del vals['file_size']
- 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)
- return result
+
+ return super(document_file, self).create(cr, uid, vals, context)
def __get_partner_id(self, cr, uid, res_model, res_id, context=None):
""" A helper to retrieve the associated partner from any res_model+id
@@ -336,7 +305,7 @@ class document_file(osv.osv):
if r:
unres.append(r)
else:
- logging.getLogger('document').warning("Unlinking attachment #%s %s that has no storage",
+ self.loggerdoc.warning("Unlinking attachment #%s %s that has no storage.",
f.id, f.name)
res = super(document_file, self).unlink(cr, uid, ids, context)
stor.do_unlink(cr, uid, unres)