Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fs_product_multi_image/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 23 additions & 0 deletions fs_product_multi_image/migrations/16.0.1.2.0/post-migrate.py
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 13 additions & 0 deletions fs_product_multi_image/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 14 additions & 3 deletions fs_product_multi_image/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading