2011-02-23 65 views
1

我想要做這樣的事情在OpenERP的報告,我怎麼會需要去創建該文件的路徑:動態添加圖片到OpenERP的RML報告文件

<image file="images\[[o.name]]" x="72" y="72"/> 

是否有辦法來創建變量在rml中,我可以提供給file =屬性。

我幾乎沒有蟒蛇知識,但很想得到解決。

現在我試圖調整order.rml,我可以加載圖像,但只有靜態...

回答

7

在報告.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> 
1

你可以做

<image>o.company_id.logo</image> 

或以任何有意義的方式引用您的圖片,人們會在訂單上顯示公司徽標,您可以將圖片字段添加到您的產品中,並在訂單的訂單項上顯示這些圖片。

+0

也沒有,如果圖像位於在OpenERP之外... – mahatmanich 2011-03-11 14:53:29

1

,你也可以做以下的

<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> 

1

既然不能在艾倫貝爾的解決方案發表意見,恐怕我要糾正他在一個單獨的答案。

艾倫寫道:你可以使用:

<image>o.company_id.logo</image> 

這是不完全正確的;你需要附上表達雙方括號像這樣:

<image>[[ o.company_id.logo ]]</image> 

因爲你可以通過對圖像標籤的屬性,我重定向你對RML文件:http://www.reportlab.com/docs/rml2pdf-userguide.pdf