Document: fix the context logic of content nodes

Content nodes should have meaningful context and perhaps an active id
'act_id', which will be used in the report or other generation fn().
The dctx mechanism of nodes was built for that, use it.

bzr revid: p_christ@hol.gr-20100713103030-irueg85zizlp42ju
This commit is contained in:
P. Christeas
2010-07-13 13:30:30 +03:00
parent 990cdf4c94
commit a7eaf3bfc9
2 changed files with 13 additions and 4 deletions
+12 -3
View File
@@ -90,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
@@ -110,6 +117,8 @@ 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()
+1 -1
View File
@@ -782,7 +782,7 @@ class node_res_obj(node_class):
self.res_find_all = parent.res_find_all
if res_bo:
self.res_id = res_bo.id
dc2 = self.context.context
dc2 = self.context.context.copy()
dc2.update(self.dctx)
dc2['res_model'] = res_model
dc2['res_id'] = res_bo.id