Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
9436 มุมมอง

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,


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

For a computed function returning arguments should keep the format

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

So please check the  rec satisfies this.



อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Inverse function on compute field แก้ไขแล้ว
1
พ.ย. 24
39618
1
ส.ค. 16
5692
3
ส.ค. 24
13622
2
ก.พ. 24
3363
2
เม.ย. 23
3265