【问题标题】:Odoo 10 - Computed image fieldOdoo 10 - 计算图像场
【发布时间】:2018-01-17 22:29:25
【问题描述】:

我想将图像字段添加到自定义模型中,其中图像是从给定的产品 ID 动态检索的

product_image = fields.Binary("Product Image", compute='_compute_product_image')

def _compute_product_image(self):
    print 'debug -compute-product-image'
    image = False
    if self.product_id:
        product_image = self.env['product.template'].search([('id', '=', self.product_id.id)]).image
        print product_image
        print type(product_image)
    print 'debug -compute-product-image end'
    return product_image

稍后在视图中:

<field name="product_image" widget="image" class="oe_avatar" readonly="True"/>

但没有显示任何内容,尽管测试的 product_id 有图像。

这是调试输出:

$ odoo -c /etc/odoo/odoo.conf -d testdatabase
debug -compute-product-image
64.78 Kb
<type 'str'>
debug -compute-product-image end

【问题讨论】:

    标签: odoo-10 odoo


    【解决方案1】:

    将图像类型 str 更改为 base64

    convertToBase64 (binaryString) {
    
                this.base64textString= btoa(binaryString);
                console.log(btoa(binaryString));
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      相关资源
      最近更新 更多