[MERGE] Merged Christophe's branch for the fix of check on duplication of documents
bzr revid: jvo@tinyerp.com-20110706124407-3x8hel6lfacmrtyo
This commit is contained in:
+15
-28
@@ -150,32 +150,25 @@ class document_file(osv.osv):
|
||||
'parent_id': __get_def_directory
|
||||
}
|
||||
_sql_constraints = [
|
||||
# filename_uniq is not possible in pure SQL
|
||||
# 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):
|
||||
def _check_duplication(self, cr, uid, ids, context=None):
|
||||
# FIXME can be a SQL constraint: unique(name,parent_id,res_model,res_id)
|
||||
for attach in self.browse(cr, uid, ids, context):
|
||||
domain = [('id', '!=', attach.id),
|
||||
('name', '=', attach.name),
|
||||
('parent_id', '=', attach.parent_id.id),
|
||||
('res_model', '=', attach.res_model),
|
||||
('res_id', '=', attach.res_id),
|
||||
]
|
||||
if self.search(cr, uid, domain, context=context):
|
||||
return False
|
||||
return True
|
||||
|
||||
_constraints = [
|
||||
(_check_duplication, 'File name must be unique!', ['name', 'parent_id', 'res_model', 'res_id'])
|
||||
]
|
||||
|
||||
def check(self, cr, uid, ids, mode, context=None, values=None):
|
||||
"""Check access wrt. res_model, relax the rule of ir.attachment parent
|
||||
|
||||
@@ -222,8 +215,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)
|
||||
@@ -260,7 +251,6 @@ class document_file(osv.osv):
|
||||
del vals['file_size']
|
||||
if len(ids) and len(vals):
|
||||
result = super(document_file,self).write(cr, uid, ids, vals, context=context)
|
||||
cr.commit() # ?
|
||||
return result
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
@@ -290,10 +280,7 @@ 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() # ?
|
||||
return result
|
||||
|
||||
def __get_partner_id(self, cr, uid, res_model, res_id, context=None):
|
||||
|
||||
Reference in New Issue
Block a user