我想在 openerp 报告中做这样的事情,我需要如何创建这个文件路径:
<image file="images\[[o.name]]" x="72" y="72"/>
有没有办法在 rml 中创建变量,然后我可以将其提供给 file= 属性。
我几乎没有python知识,但很想解决这个问题。
现在我正在尝试调整 order.rml,我可以加载图像,但只能静态加载......
在报告 .py 文件中添加一个 Python 函数,如下所示:
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
在 rml 本身中调用该函数:
<para>[[ image_url(o['id']) and setTag('para','image') or removeParentNode('para') ]][[ image_url(o['id']) ]]</para>
你可以做
<image>o.company_id.logo</image>
或以任何有意义的方式引用您的图像,将在订单上显示公司徽标,您可以将图像字段添加到您的产品中,并根据需要在订单的行项目上显示这些字段。
你也可以在
<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>
由于我无法评论艾伦贝尔的解决方案,恐怕我必须在单独的答案中纠正他。
艾伦写道,你可以使用:
<image>o.company_id.logo</image>
这并不完全正确;您需要将表达式括在方括号中,如下所示:
<image>[[ o.company_id.logo ]]</image>
对于您可以传递给图像标签的属性,我将您重定向到 RML 文档:http ://www.reportlab.com/docs/rml2pdf-userguide.pdf