diff --git a/addons/document/directory_content.py b/addons/document/directory_content.py index 2d434712f56..bec4f25e45d 100644 --- a/addons/document/directory_content.py +++ b/addons/document/directory_content.py @@ -58,7 +58,9 @@ class document_directory_content(osv.osv): 'suffix': fields.char('Suffix', size=16), 'report_id': fields.many2one('ir.actions.report.xml', 'Report'), 'extension': fields.selection(_extension_get, 'Document Type', required=True, size=4), - 'include_name': fields.boolean('Include Record Name', help="Check this field if you want that the name of the file start by the record name."), + 'include_name': fields.boolean('Include Record Name', + help="Check this field if you want that the name of the file to contain the record name." \ + "\nIf set, the directory will have to be a resource one."), 'directory_id': fields.many2one('document.directory', 'Directory'), } _defaults = { @@ -88,12 +90,19 @@ class document_directory_content(osv.osv): tname = (content.prefix or '') + (content.suffix or '') + (content.extension or '') if tname.find('/'): tname=tname.replace('/', '_') + act_id = False + if 'dctx_res_id' in node.dctx: + act_id = node.dctx['dctx_res_id'] + elif hasattr(node, 'res_id'): + act_id = node.res_id + else: + act_id = node.context.context.get('res_id',False) if not nodename: - n = nodes.node_content(tname, node, node.context,content) + n = nodes.node_content(tname, node, node.context,content, act_id=act_id) res2.append( n) else: if nodename == tname: - n = nodes.node_content(tname, node, node.context,content) + n = nodes.node_content(tname, node, node.context,content, act_id=act_id) n.fill_fields(cr) res2.append(n) return res2 @@ -108,6 +117,10 @@ class document_directory_content(osv.osv): raise Exception("Invalid content: %s" % node.extension) report = self.pool.get('ir.actions.report.xml').browse(cr, uid, node.report_id) srv = netsvc.Service._services['report.'+report.report_name] - pdf,pdftype = srv.create(cr, uid, [node.context.context['res_id']], {}, {}) + ctx = node.context.context.copy() + ctx.update(node.dctx) + pdf,pdftype = srv.create(cr, uid, [node.act_id,], {}, context=ctx) return pdf document_directory_content() + +#eof \ No newline at end of file diff --git a/addons/document/document.py b/addons/document/document.py index 6ab6cae5281..ac3d7b9187d 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -47,7 +47,10 @@ class document_file(osv.osv): def _data_get(self, cr, uid, ids, name, arg, context): fbrl = self.browse(cr, uid, ids, context=context) - nctx = nodes.get_node_context(cr, uid, context) + nctx = nodes.get_node_context(cr, uid, context={}) + # nctx will /not/ inherit the caller's context. Most of + # it would be useless, anyway (like active_id, active_model, + # bin_size etc.) result = {} bin_size = context.get('bin_size', False) for fbro in fbrl: @@ -67,7 +70,7 @@ class document_file(osv.osv): if not value: return True fbro = self.browse(cr, uid, id, context=context) - nctx = nodes.get_node_context(cr, uid, context) + nctx = nodes.get_node_context(cr, uid, context={}) fnode = nodes.node_file(None, None, nctx, fbro) res = fnode.set_data(cr, base64.decodestring(value), fbro) return res @@ -156,7 +159,7 @@ class document_file(osv.osv): raise osv.except_osv(_('ValidateError'), _('File name must be unique!')) if ('parent_id' in vals) or ('name' in vals): # perhaps this file is renaming or changing directory - nctx = nodes.get_node_context(cr,uid,context) + nctx = nodes.get_node_context(cr,uid,context={}) dirobj = self.pool.get('document.directory') if 'parent_id' in vals: dbro = dirobj.browse(cr, uid, vals['parent_id'], context=context) diff --git a/addons/document/document_directory.py b/addons/document/document_directory.py index 0685f5c08ff..f5b9202fc8e 100644 --- a/addons/document/document_directory.py +++ b/addons/document/document_directory.py @@ -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 !'), diff --git a/addons/document/document_view.xml b/addons/document/document_view.xml index 693d7370567..998d1e93188 100644 --- a/addons/document/document_view.xml +++ b/addons/document/document_view.xml @@ -82,6 +82,7 @@ + @@ -96,7 +97,7 @@