Files
odoo_source/addons/website_theme_install/models/ir_module_module.py
T
qsm-odoo dbd0255228 [FIX] website_theme_install: language dependant code
The module did only work in english because the themes were found
amongst the applications thanks to their categorie names.

Solution is to search categories thanks to their xml_id :
base.module_category_theme or base.module_category_theme_...
and not
base.module_category_hidden or base.module_category_theme_hidden
2016-01-13 15:10:02 +01:00

52 lines
2.3 KiB
Python

import os
from openerp import api, fields, models, _
class IrModuleModule(models.Model):
_name = "ir.module.module"
_inherit = _name
image_ids = fields.One2many('ir.attachment', 'res_id',
domain=[('res_model', '=', _name), ('mimetype', '=like', 'image/%')],
string='Screenshots', readonly=True)
@api.model
def update_list(self, context=None):
res = super(IrModuleModule, self).update_list(context=context)
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)
images = terp.get('images', [])
for image in images:
image_path = os.path.join(app.name, image)
if image_path not in existing_urls:
image_name = os.path.basename(image_path)
IrAttachment.create({
'type': 'url',
'name': image_name,
'datas_fname': image_name,
'url': image_path,
'res_model': self._name,
'res_id': app.id,
})
return res
@api.multi
def button_choose_theme(self, context):
theme_category_id = self.env.ref('base.module_category_theme').id
self.search([ # Uninstall the theme(s) which is (are) installed
('state', '=', 'installed'),
'|', ('category_id', 'not in', [self.env.ref('base.module_category_hidden').id, self.env.ref('base.module_category_theme_hidden').id]), ('name', '=', 'theme_default'),
'|', ('category_id', '=', theme_category_id), ('category_id.parent_id', '=', theme_category_id)
]).button_immediate_uninstall(context=context)
next_action = self.button_immediate_install(context=context) # Then install the new chosen one
if next_action.get('tag') == 'reload' and not next_action.get('params', {}).get('menu_id'):
next_action = self.env.ref('website.action_website_tutorial').read()[0]
return next_action