From c86bff6a02617ca1f06a3dadf21924e7e38f5877 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Thu, 19 Dec 2019 16:05:29 +0000 Subject: [PATCH] [IMP] website: load theme images also when module install through CLI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Themes image would not be shown correctly in the theme selection if the `website` module was installed in CLI. Indeed, the code supposed to load the theme images was done in the kanban view during theme selection after installing module through apps screen. Now, this code is encapsulated and called in post_init hook of website. This was also needed for an improvement on `test_themes` module, see https://github.com/odoo/design-themes/pull/195. closes odoo/odoo#42206 Signed-off-by: Jérémy Kersten (jke) --- addons/website/__init__.py | 5 ++++ addons/website/__manifest__.py | 1 + addons/website/models/ir_module_module.py | 17 +++++++---- .../views/website_navbar_templates.xml | 2 +- addons/website/views/website_views.xml | 29 +++++++------------ 5 files changed, 30 insertions(+), 24 deletions(-) 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 @@
  • -
  • +
  • diff --git a/addons/website/views/website_views.xml b/addons/website/views/website_views.xml index fc39f9e45ec..7b92417e49b 100644 --- a/addons/website/views/website_views.xml +++ b/addons/website/views/website_views.xml @@ -380,24 +380,6 @@ - - Config: Choose Your Theme - - code - -model.update_list() -action = { - 'type': 'ir.actions.act_url', - 'url': '/web?reload#action=website.theme_install_kanban_action', # the ?reload option is there to fool the webclient into thinking it is a different location and so to force a reload - 'target': 'self', -} - - - - - 0 - - website.form ir.module.module @@ -430,6 +412,17 @@ action = { ]"/> + + Website + /web?reload#action=website.theme_install_kanban_action + self + + + + + 0 + +