diff --git a/addons/website/__init__.py b/addons/website/__init__.py index dcd5ec789d0..748058ff042 100644 --- a/addons/website/__init__.py +++ b/addons/website/__init__.py @@ -20,3 +20,8 @@ def uninstall_hook(cr, registry): ('model', '=', 'res.config.settings'), ]).unlink() cr.after('commit', partial(rem_website_id_null, cr.dbname)) + + +def post_init_hook(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + env['ir.module.module'].update_theme_images() diff --git a/addons/website/__manifest__.py b/addons/website/__manifest__.py index 6f6bf404aa5..6f4ec0e5bd3 100644 --- a/addons/website/__manifest__.py +++ b/addons/website/__manifest__.py @@ -79,5 +79,6 @@ 'static/src/xml/theme_preview.xml', ], 'application': True, + 'post_init_hook': 'post_init_hook', 'uninstall_hook': 'uninstall_hook', } diff --git a/addons/website/models/ir_module_module.py b/addons/website/models/ir_module_module.py index 1e8ec1fe5e9..86286a9fd2c 100644 --- a/addons/website/models/ir_module_module.py +++ b/addons/website/models/ir_module_module.py @@ -373,16 +373,24 @@ class IrModuleModule(models.Model): @api.model def update_list(self): res = super(IrModuleModule, self).update_list() + self.update_theme_images() + return res + @api.model + def update_theme_images(self): IrAttachment = self.env['ir.attachment'] existing_urls = IrAttachment.search_read([['res_model', '=', self._name], ['type', '=', 'url']], ['url']) existing_urls = [url_wrapped['url'] for url_wrapped in existing_urls] - for app in self.search([]): - terp = self.get_module_info(app.name) + themes = self.env['ir.module.module'].with_context(active_test=False).search([ + ('category_id', 'child_of', self.env.ref('base.module_category_theme').id), + ], order='name') + + for theme in themes: + terp = self.get_module_info(theme.name) images = terp.get('images', []) for image in images: - image_path = os.path.join(app.name, image) + image_path = os.path.join(theme.name, image) if image_path not in existing_urls: image_name = os.path.basename(image_path) IrAttachment.create({ @@ -390,6 +398,5 @@ class IrModuleModule(models.Model): 'name': image_name, 'url': image_path, 'res_model': self._name, - 'res_id': app.id, + 'res_id': theme.id, }) - return res diff --git a/addons/website/views/website_navbar_templates.xml b/addons/website/views/website_navbar_templates.xml index d4628378b68..e32dff679f3 100644 --- a/addons/website/views/website_navbar_templates.xml +++ b/addons/website/views/website_navbar_templates.xml @@ -75,7 +75,7 @@