通过QWeb报表上的fields.function从数据库获取图像-Odoo 8 [英] Get images from db by fields.function on QWeb report - Odoo 8

查看:63
本文介绍了通过QWeb报表上的fields.function从数据库获取图像-Odoo 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的数据库中的任何图像打印通过fields.function获取的图像.

I want to print an image getting it by a fields.function for any image in my database.

我正在尝试以下操作:

def _get_image(self, cr, uid, ids, name, args, context=None):
    res = dict.fromkeys(ids)
    for record_browse in self.browse(cr, uid, ids):
        partner = self.pool.get('res.partner').browse(cr,uid,6,context=None).image
        res[record_browse.id] = base64.encodestring(partner)
    return res   

_columns = {
        'image': fields.function(_get_image, string="Image", type="binary"),
}

但是在qweb报告中我得到了:

but in qweb report I got:

  File "/opt/*/openerp/addons/base/ir/ir_qweb.py", line 791, in value_to_html
raise ValueError("Non-image binary fields can not be converted to HTML")
ValueError: Non-image binary fields can not be converted to HTML

如果我以某种形式打印图像,则一切正常.

If I print the image in a form, everything is going well.

我们将不胜感激,在此先感谢您.

Any help would be appreciated, thanks in advance.

推荐答案

尝试以下代码:

def _get_image(self, cr, uid, ids, name, args, context=None):
    res = dict.fromkeys(ids)
    for record_browse in self.browse(cr, uid, ids):
        partner = self.pool.get('res.partner').browse(cr,uid,6,context=None).image
        res[record_browse.id] = base64.encodestring(partner)
    return res   

_columns = {
        'image': fields.binary("Image"),
        'image_x': fields.function(_get_image, string="Image", type="binary"),

}

这篇关于通过QWeb报表上的fields.function从数据库获取图像-Odoo 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆