Skip to Content
Menu
This question has been flagged
1 Reply
2266 Views

I would like to create a new image size (large), as we need one more for better load speed.

In a model that inherits `product.product` I have added this code:

image_large = fields.Binary(
"Large-sized image", compute='_compute_images', inverse='_set_image_large',
help="Image of the product variant (Large-sized image of product template if false).")

@api.one
@api.depends('image_variant', 'product_tmpl_id.image')
def _compute_images(self):
if self._context.get('bin_size'):
self.image_large = self.image_variant
self.image_medium = self.image_variant
self.image_small = self.image_variant
self.image = self.image_variant
else:
resized_images = tools.image_get_resized_images(self.image_variant, return_big=True, avoid_resize_medium=True)
self.image_large = resized_images['image_large']
self.image_medium = resized_images['image_medium']
self.image_small = resized_images['image_small']
self.image = resized_images['image']
if not self.image_large:
self.image_large = self.product_tmpl_id.image_large
if not self.image_medium:
self.image_medium = self.product_tmpl_id.image_medium
if not self.image_small:
self.image_small = self.product_tmpl_id.image_small
if not self.image:
self.image = self.product_tmpl_id.image


And tried to add it to tools

image.image_resize_image_large = image_resize_image_large
tools.image_resize_image_large = image_resize_image_large


But I get a key error on image_large.

Any suggestions on how to add a new image size?

Avatar
Discard
Related Posts Replies Views Activity
0
Feb 24
456
1
Nov 24
18017
1
Sep 23
1200
3
May 23
4087
7
Apr 23
47087