get_installed and _lang_get_id are both ormcached and correctly check the context Retrieving a res.lang from a code is a frequent action that can be achieved with _lang_get (cf previous commit). Using _lang_get ensure the active_test in the context is correct and is not poluted with another context propagation issue. odoo/odoo#35490 discussion is an example of bad context propagation closes odoo/odoo#35504 Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
# -*- encoding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class BaseLanguageInstall(models.TransientModel):
|
|
|
|
_inherit = "base.language.install"
|
|
|
|
website_ids = fields.Many2many('website', string='Websites to translate')
|
|
|
|
@api.model
|
|
def default_get(self, fields):
|
|
defaults = super(BaseLanguageInstall, self).default_get(fields)
|
|
website_id = self._context.get('params', {}).get('website_id')
|
|
if website_id:
|
|
if 'website_ids' not in defaults:
|
|
defaults['website_ids'] = []
|
|
defaults['website_ids'].append(website_id)
|
|
return defaults
|
|
|
|
def lang_install(self):
|
|
action = super(BaseLanguageInstall, self).lang_install()
|
|
lang = self.env['res.lang']._lang_get(self.lang)
|
|
if self.website_ids and lang:
|
|
self.website_ids.write({'language_ids': [(4, lang.id)]})
|
|
params = self._context.get('params', {})
|
|
if 'url_return' in params:
|
|
return {
|
|
'url': params['url_return'].replace('[lang]', self.lang),
|
|
'type': 'ir.actions.act_url',
|
|
'target': 'self'
|
|
}
|
|
return action
|