Ayuda

0

How to resize image in existing record ?

Avatar
Jignesh Mehta

Hello,


I have 1 custom class which have minimum 30000 record which have images are stored.

Now, I want to resize all the images which is stored and also creating new record with image.


First image field is like as below

variants_image_medium = fields.Binary('Product Image', store=True, attachment=True)


Now, I converted image field as shown below

variants_image_medium = fields.Binary('Product Image', inverse='_compute_images', store=True, attachment=True, readonly=False)


@api.multi
def _compute_images(self):
        for rec in self:
            if rec.variants_image_medium:
                image = tools.image_resize_image_small(rec.variants_image_medium)
                rec.variants_image_medium = image
                return rec


 It gives me error,

RuntimeError: maximum recursion depth exceeded


How to Solve that error ?

Thanks in Advance,


1 Comentario
Avatar
Descartar
3 Respuestas
1
Best Answer

For a computed function returning arguments should keep the format

{'value':
     { 'field_name':field_value}
}

So please check the  rec satisfies this.



Avatar
Descartar
0
Avatar
IT Libertas LLC
Best Answer

In your inverse you are changing current field, what invokes this inverse recursively:

Field value x > Field value x1 > Field value x2 > .... > 


You should

1) either store resized image in a separated field

2) or add a condition in inverse not to make recursion, e.g.:

already_resized = fields.Boolean()

@api.multi
def _compute_images(self):
        for rec in self:
            if not 
already_resized and rec.variants_image_medium:

                image = tools.image_resize_image_small(rec.variants_image_medium)
                rec.variants_image_medium = image
                rec.
already_resized = True

Avatar
Descartar