diff --git a/product.py b/product.py index 86095ebb4d..f70e44ce5b 100644 --- a/product.py +++ b/product.py @@ -47,9 +47,12 @@ class ImageURLMixin: })) if args: size = args.pop('s', None) + index = args.pop('i', None) args = {k: int(bool(v)) for k, v in args.items()} if size: args['s'] = size + if index is not None: + args['i'] = index url += '?' + urlencode(args) return url diff --git a/tests/test_module.py b/tests/test_module.py index 45450a9c39..9a670ba642 100644 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -40,5 +40,30 @@ class ProductImageTestCase(ModuleTestCase): img = PIL.Image.open(io.BytesIO(image.get(size=100))) self.assertEqual(img.size, (100, 100)) + @with_transaction() + def test_get_image_url(self): + "Test get_image_url" + pool = Pool() + Image = pool.get('product.image') + Template = pool.get('product.template') + Uom = pool.get('product.uom') + + template = Template(name="Template", code="CODE") + template.default_uom, = Uom.search([], limit=1) + template.save() + + for _ in range(3): + image = Image(template=template) + image.image = urllib.request.urlopen( + 'https://picsum.photos/200').read() + image.save() + + self.assertRegex( + template.get_image_url(i=2), + r'/product/image/CODE/.*/Template\?i=2') + self.assertRegex( + template.get_image_url(s=400), + r'/product/image/CODE/.*/Template\?s=400') + del ModuleTestCase