Hi
here my situation
class ProductImage(models.Model):
_name = "product.images"
_description = "Additional Product Images"
_order = "sequence"
sequence = fields.Integer('Sequence',)
product_id = fields.Many2one('product.product', 'Product Variant', required=False)
product_tmpl_id = fields.Many2one('product.template', 'Product Template', required=False)
name = fields.Char('Image Name', size=160)
image = fields.Binary("Image", attachment=True, required=True)
and on Product model
image_ids = fields.One2many('product.images',
'product_id',
'Additional Images')
I'd like to replace the default image on product form with (for example) the first image from image_ids.
So I've created a computed method
@api.depends('image_ids')
def _compute_main_image(self):
if self.id and self.image_ids:
self.main_image = self.image_ids[0]
for a new Binary field
main_image = fields.Binary("Main image",
compute='_compute_main_image',
store=False, )
and I'm trying to show that image on the form
<xpath expr="//field[@name='image_medium']" position="attributes">
<field name="main_image" widget="image" class="oe_avatar"/>
</xpath>
but I received "The image couldn't display ..."
can someone help me?
Thank's.
Pietro Conconi
main_image should be a binary field and you should give binary values