diff --git a/fs_product_multi_image/__manifest__.py b/fs_product_multi_image/__manifest__.py index a08483aa77..785b8018bf 100644 --- a/fs_product_multi_image/__manifest__.py +++ b/fs_product_multi_image/__manifest__.py @@ -5,7 +5,7 @@ "name": "Fs Product Multi Image", "summary": """ Manage multi images from extenal file system on product""", - "version": "16.0.1.1.6", + "version": "16.0.1.2.0", "license": "AGPL-3", "author": "ACSONE SA/NV,Odoo Community Association (OCA)", "website": "https://github.com/OCA/storage", diff --git a/fs_product_multi_image/migrations/16.0.1.2.0/post-migrate.py b/fs_product_multi_image/migrations/16.0.1.2.0/post-migrate.py new file mode 100644 index 0000000000..6ab8a46737 --- /dev/null +++ b/fs_product_multi_image/migrations/16.0.1.2.0/post-migrate.py @@ -0,0 +1,23 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import logging + +try: + from odoo.upgrade import util +except ImportError as error: + raise ImportError( + "This migration script requires odoo.upgrade.util.\n" + "Please install odoo.upgrade.util to proceed with the migration.\n" + "See https://github.com/odoo/upgrade-util/" + ) from error + + +_logger = logging.getLogger(__name__) + + +def migrate(cr, version): + if not version: + return + _logger.info("Recompute main_image_id for product.template records") + util.recompute_fields(cr, "product.template", ["main_image_id"], logger=_logger) diff --git a/fs_product_multi_image/models/product_product.py b/fs_product_multi_image/models/product_product.py index fd87e9a7d9..1e19719e05 100644 --- a/fs_product_multi_image/models/product_product.py +++ b/fs_product_multi_image/models/product_product.py @@ -38,6 +38,19 @@ class ProductProduct(models.Model): store=False, ) + # Compatibility field for standard modules (especially website_sale) + # The sole purpose of this field is to provide the field image_128 + # that can be resolved by the web controller when requested + # to provide the image_128 content of a product.product record. + # By using a related field of the same type (FSImage) as image_medium, + # we avoid any extra cost of computing the image_128 content + image_128 = FSImage( + string="Image 128", + related="image_medium", + readonly=True, + store=False, + ) + @api.depends( "product_tmpl_id.image_ids", "product_tmpl_id.image_ids.sequence", diff --git a/fs_product_multi_image/models/product_template.py b/fs_product_multi_image/models/product_template.py index 3ed6c44de0..6122ed916e 100644 --- a/fs_product_multi_image/models/product_template.py +++ b/fs_product_multi_image/models/product_template.py @@ -33,10 +33,21 @@ class ProductTemplate(models.Model): store=False, ) + # Compatibility field for standard modules (especially website_sale) + # The sole purpose of this field is to provide the field image_128 + # that can be resolved by the web controller when requested + # to provide the image_128 content of a product.product record. + # By using a related field of the same type (FSImage) as image_medium, + # we avoid any extra cost of computing the image_128 content + image_128 = FSImage( + string="Image 128", + related="image_medium", + readonly=True, + store=False, + ) + @api.depends("image_ids", "image_ids.sequence") def _compute_main_image_id(self): for record in self: - image_ids = record.image_ids.sorted( - key=lambda i: f"{i.sequence},{str(i.id)}" - ) + image_ids = record.image_ids.sorted(key=lambda i: (i.sequence, i.id)) record.main_image_id = image_ids and image_ids[0] or None