Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
9438 Lượt xem

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,


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

For a computed function returning arguments should keep the format

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

So please check the  rec satisfies this.



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 11 24
39619
1
thg 8 16
5692
3
thg 8 24
13622
2
thg 2 24
3364
2
thg 4 23
3270