Files
odoo_source/addons/website_theme_install/models/ir_module_module.py
T
Martin Trigaux 11812b0b9e [FIX] all: remove external ids fakely from base
Several modules defines records with the external ID `base.foo_bar` while it is
created inside this module (typically menus and groups).
While there is no technical reasons to do so but this may introduce issues:

- these records will not be deleted during uninstall
- if a language is loaded before the installation of the module, it won't be
  translated

The uninstallation will only remove the records with an external id linked to
this module (these would only be removed when removing base).

Installing a language before the module will drop the translations not linked
to an existing external id (as it can not be resolved).

This commit correct all the external ids tagged as from base or other incorrect
modules.
2016-09-02 16:14:26 +02:00

57 lines
2.3 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import os
from odoo 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):
res = super(IrModuleModule, self).update_list()
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):
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('website_theme_install.module_category_theme_hidden').id]), ('name', '=', 'theme_default'),
'|', ('category_id', '=', theme_category_id), ('category_id.parent_id', '=', theme_category_id)
]).button_immediate_uninstall()
next_action = self.button_immediate_install() # 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').read()[0]
return next_action