adding images dynamically to an openerp rml report file
I want to do something like this in a openerp report, how would I need to go about to create this file path:
<image file="images\[[o.name]]" x="72" y="72"/>
Are there ways to create variables in rml that I could then feed to the file= attribute.
I have little to no python knowledge, but would love to get this solved.
开发者_开发知识库Right now I am trying to adjust the order.rml, I can load images, but only statically ...
In the reports .py file add a python function like this:
self.localcontext.update({
'time': time,
'image_url' : self._get_imagepath,
})
def _get_imagepath(self,product):
attach_ids = self.pool.get('ir.attachment').search(self.cr, self.uid, [('res_model','=','product.product'), ('res_id', '=',product)])
datas = self.pool.get('ir.attachment').read(self.cr, self.uid, attach_ids)
if len(datas):
# if there are several, pick first
try:
if datas[0]['link']:
try:
img_data = base64.encodestring(urllib.urlopen(datas[0]['link']).read())
return img_data
except Exception,innerEx:
print innerEx
elif datas[0]['datas']:
return datas[0]['datas']
except Exception,e:
print e
return None
in the rml itself call the function as such:
<para>[[ image_url(o['id']) and setTag('para','image') or removeParentNode('para') ]][[ image_url(o['id']) ]]</para>
you can just do
<image>o.company_id.logo</image>
or reference your image in whatever way makes sense, that one will display the company logo on an order form, you could add image fields to your products and display those on the line items of the order if you want.
also you can do the following in
<header>
<pageTemplate>
<frame id="first" x1="1.3cm" y1="2.5cm" height="23.0cm" width="19cm"/>
<pageGraphics>
<image file= "/home/workspace/openERP/src/openerp-server/pixmaps/client-logo.png" x="3.3cm" y="3.5cm" height="32.0"/>
</pageGraphics>
</pageTemplate>
Since I can not comment on Alan Bell's solution, I'm afraid I have to correct him in a separate answer.
Alan wrote you can just use:
<image>o.company_id.logo</image>
This is not entirely correct; you need to enclose the expression in double square brackets like so:
<image>[[ o.company_id.logo ]]</image>
For the attributes you can pass to the image tag, I redirect you towards the RML documentation: http://www.reportlab.com/docs/rml2pdf-userguide.pdf
精彩评论