0
votes

I want to add an image field to a custom model where the image is dynamically retrieved from a given product 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

Later in the view:

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

But nothing is displayed, despite the tested product_id has an image.

This is debug output:

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

1 Answers

0
votes

change image type str to base64

convertToBase64 (binaryString) {

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