Skip to Content
Menu
This question has been flagged

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







Avatar
Discard

main_image should be a binary field and you should give binary values

Author Best Answer

thank U

it works!

Avatar
Discard
Related Posts Replies Views Activity
3
May 23
15261
1
Mar 15
5598
1
Apr 15
3986
2
Feb 24
1397
1
Jun 22
2158