Files
odoo_source/odoo/addons/test_convert/models.py
T
Denis Ledoux 70a8758760 [FIX] core: convert_file and xml_import must ingore env.lang
Before revision 5bf1207c8c
a new environment was created for each call
at `xml_import` or `convert_file`,
with `odoo.api.Environment(cr, SUPERUSER_ID, {})`
meaning the context was empty, meaning the lang was never set

Now that we pass from end to end the environment,
the caller of `xml_import` or `convert_file`
passes his own environment, therefore propagating
his `context` variables, therefore potentially passing
a lang in the context.

Therefore, since this change, the lang of the user
is taken into account when calling `xml_import`/`convert_file`,
and it updates the translation term rather than the source term
for translated fields.

This could be an actual/intended valid behavior,
this needs to be discussed,
but currently the places where `xml_import`/`convert_file`
is called expects to update the source term,
not the translated term.
See for reference
https://github.com/odoo/odoo/pull/116780#issuecomment-1486506663

Therefore, as this is an unexpected/unintended change of behavior
of the refactor 5bf1207c8c,
and as code blocks calling `xml_import`/`convert_file` have not
been adapted, we prefer to play it safe
and revert the behavior to what is was.

This is very possible other context keys will need to be dropped,
but one of the desired change of the refactor was to be
able to pass keys in the context, currently we prefer
to not wipe the environment context and just blacklist the one we
do not want to propagate, such as the lang.
If other related issues arise, we will then re-consider.

closes odoo/odoo#117621

X-original-commit: 44fa57e52fbc853b7756a96c73c94baa469c99ca
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
2023-04-04 16:02:09 +02:00

40 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class TestModel(models.Model):
_name = 'test_convert.test_model'
_description = "Test Convert Model"
name = fields.Char(translate=True)
usered_ids = fields.One2many('test_convert.usered', 'test_id')
@api.model
def action_test_date(self, today_date):
return True
@api.model
def action_test_time(self, cur_time):
return True
@api.model
def action_test_timezone(self, timezone):
return True
class Usered(models.Model):
_name = 'test_convert.usered'
_description = "z test model ignore"
name = fields.Char()
user_id = fields.Many2one('res.users', default=lambda self: self.env.user)
test_id = fields.Many2one('test_convert.test_model')
tz = fields.Char(default=lambda self: self.env.context.get('tz') or self.env.user.tz)
@api.model
def model_method(self, *args, **kwargs):
return self, args, kwargs
def method(self, *args, **kwargs):
return self, args, kwargs