Document directory: "find_all" field for resource dirs.

A (mis-)feature of the previous code was that in resource directories, it
would only list attachments that would have those dirs as parents. This
means that we couldn't have another categorisation, that would yield some
of the same attachments.

bzr revid: p_christ@hol.gr-20100713102958-nk40nckc41uxyzri
This commit is contained in:
P. Christeas 2010-07-13 13:29:58 +03:00
parent 403a71fbaa
commit 2d3d861a3e
3 changed files with 14 additions and 2 deletions

View File

@ -57,6 +57,9 @@ class document_directory(osv.osv):
'ressource_type_id': fields.many2one('ir.model', 'Resource model',
help="Select an object here and there will be one folder per record of that resource."),
'resource_field': fields.many2one('ir.model.fields', 'Name field', help='Field to be used as name on resource directories. If empty, the "name" will be used.'),
'resource_find_all': fields.boolean('Find all resources', required=True,
help="If true, all attachments that match this resource will " \
" be located. If false, only ones that have this as parent." ),
'ressource_parent_type_id': fields.many2one('ir.model', 'Parent Model',
help="If you put an object here, this directory template will appear bellow all of these objects. " \
"Don't put a parent directory if you select a parent model."),
@ -103,6 +106,7 @@ class document_directory(osv.osv):
'type': lambda *args: 'directory',
'ressource_id': lambda *a: 0,
'storage_id': _get_def_storage,
'resource_find_all': True,
}
_sql_constraints = [
('dirname_uniq', 'unique (name,parent_id,ressource_id,ressource_parent_type_id)', 'The directory name must be unique !'),

View File

@ -82,6 +82,7 @@
<group colspan="4" col="4" attrs="{'invisible': [('type','!=','ressource')]}">
<field name="ressource_type_id" on_change="onchange_content_id(ressource_type_id)"
attrs="{'required': [('type','=','ressource')] }"/>
<field name="resource_find_all" groups="base.group_extended" />
<newline/>
<field name="resource_field" domain="[('model_id','=',ressource_type_id), ('ttype', 'in', ('char', 'selection', 'date', 'datetime'))]"/>
<field name="ressource_tree"/>

View File

@ -657,6 +657,7 @@ class node_res_dir(node_class):
self.uidperms = dirr.get_dir_permissions()
self.res_model = dirr.ressource_type_id and dirr.ressource_type_id.model or False
self.resm_id = dirr.ressource_id
self.res_find_all = dirr.resource_find_all
self.namefield = dirr.resource_field.name or 'name'
self.displayname = dirr.name
# Important: the domain is evaluated using the *parent* dctx!
@ -771,13 +772,14 @@ class node_res_obj(node_class):
self.write_date = parent.write_date
self.content_length = 0
self.unixperms = 040750
self.uidperms = parent.uidperms & 0x15
self.uidperms = parent.uidperms & 15
self.uuser = parent.uuser
self.ugroup = parent.ugroup
self.res_model = res_model
self.domain = parent.domain
self.displayname = path
self.dctx_dict = parent.dctx_dict
self.res_find_all = parent.res_find_all
if res_bo:
self.res_id = res_bo.id
dc2 = self.context.context
@ -806,6 +808,8 @@ class node_res_obj(node_class):
return False
if self.domain != other.domain:
return False
if self.res_find_all != other.res_find_all:
return False
if self.dctx != other.dctx:
return False
return self.dir_id == other.dir_id
@ -919,6 +923,8 @@ class node_res_obj(node_class):
fil_obj = dirobj.pool.get('ir.attachment')
if self.res_find_all:
where2 = where
where3 = where2 + [('res_model', '=', self.res_model), ('res_id','=',self.res_id)]
# print "where clause for dir_obj", where2
ids = fil_obj.search(cr, uid, where3, context=ctx)
@ -986,11 +992,12 @@ class node_res_obj(node_class):
val = {
'name': path,
'datas_fname': path,
'parent_id': self.dir_id,
'res_model': self.res_model,
'res_id': self.res_id,
# Datas are not set here
}
if not self.res_find_all:
val['parent_id'] = self.dir_id
fil_id = fil_obj.create(cr, uid, val, context=ctx)
fil = fil_obj.browse(cr, uid, fil_id, context=ctx)