From 8a3315a63ec50f9ef26832d05a25bcc629481620 Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Thu, 4 Apr 2024 14:42:11 +0200 Subject: [PATCH] [FIX] website: preserve theme images order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The image displayed in the theme selection page is the last one that was created out of the theme's manifest's `images` entry. Because of this, when a theme has a different non-last image in a new version compared to an old version, that image becomes the last created one and is displayed in the theme selection page instead of the expected screenshot image. This commit preserves the order that was specified in the `images` definition by re-creating all images instead of only the modified ones - if an update is needed at all. Steps to reproduce: - Install `website` with a theme in 14.0. - Upgrade to 15.0. - Go to the theme selection page. => Some themes (e.g. `theme_beauty`) displayed their cover picture instead of their screenshot. task-2719425 closes odoo/odoo#163118 X-original-commit: 4bc165b68078638a8057c79162f428026ca81321 Signed-off-by: Soukéina Bojabza (sobo) --- addons/website/models/ir_module_module.py | 25 ++++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/addons/website/models/ir_module_module.py b/addons/website/models/ir_module_module.py index 56eea99a3aa..02bd4032a0b 100644 --- a/addons/website/models/ir_module_module.py +++ b/addons/website/models/ir_module_module.py @@ -2,7 +2,6 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import logging -import os from collections import defaultdict, OrderedDict from odoo import api, fields, models @@ -446,17 +445,19 @@ class IrModuleModule(models.Model): theme._generate_primary_snippet_templates() terp = self.get_module_info(theme.name) images = terp.get('images', []) - for image in images: - image_path = '/' + os.path.join(theme.name, image) - if image_path not in existing_urls: - image_name = os.path.basename(image_path) - IrAttachment.create({ - 'type': 'url', - 'name': image_name, - 'url': image_path, - 'res_model': self._name, - 'res_id': theme.id, - }) + image_paths = ['/%s/%s' % (theme.name, image) for image in images] + if all(image_path in existing_urls for image_path in image_paths): + continue + # Images creation order must be the order specified in the manifest + for image_path in image_paths: + image_name = image_path.split('/')[-1] + IrAttachment.create({ + 'type': 'url', + 'name': image_name, + 'url': image_path, + 'res_model': self._name, + 'res_id': theme.id, + }) def get_themes_domain(self): """Returns the 'ir.module.module' search domain matching all available themes."""