简体   繁体   English

动态将图像添加到openerp rml报告文件

[英]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: 我想在openerp报表中执行以下操作,如何创建该文件路径:

<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. 有没有什么方法可以在rml中创建变量,然后将其提供给file =属性。

I have little to no python knowledge, but would love to get this solved. 我几乎没有Python知识,但很想解决这个问题。

Right now I am trying to adjust the order.rml, I can load images, but only statically ... 现在,我正在尝试调整order.rml,可以加载图像,但只能静态加载...

In the reports .py file add a python function like this: 在报告.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

in the rml itself call the function as such: 在rml本身中这样调用函数:

<para>[[ image_url(o['id']) and setTag('para','image') or removeParentNode('para') ]][[ image_url(o['id']) ]]</para>

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 Bell的解决方案,因此我不得不在一个单独的答案中纠正他。

Alan wrote you can just use: 艾伦(Alan)写道您可以使用:

<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 对于可以传递给图像标签的属性,我将您重定向到RML文档: http : //www.reportlab.com/docs/rml2pdf-userguide.pdf

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. 或以任何有意义的方式引用您的图片,以便在订单上显示公司徽标,您可以在产品中添加图片字段,并根据需要在订单的订单项上显示图片字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM