[MERGE] forward port of branch 7.0 up to revid 5148 mat@openerp.com-20131125125008-wmpssjk5vygdcc0w

bzr revid: chs@openerp.com-20131125151017-lmj53bxg1pfrr4a7
This commit is contained in:
Christophe Simonis 2013-11-25 16:10:17 +01:00
commit 3211a29d9b
4 changed files with 23 additions and 19 deletions

View File

@ -340,10 +340,10 @@ class test_translation(common.TransactionCase):
self.new_fr_cat_id = self.res_category.copy(cr, uid, self.cat_id, default={'name': 'Clients (copie)'}, context={'lang':'fr_FR'})
no_context_cat = self.res_category.browse(cr, uid, self.new_fr_cat_id)
self.assertEqual(no_context_cat.name, 'Clients (copie)', "Duplication with default value not applied")
self.assertEqual(no_context_cat.name, 'Customers', "Duplication erased original untranslated value")
fr_context_cat = self.res_category.browse(cr, uid, self.new_fr_cat_id, context={'lang':'fr_FR'})
self.assertEqual(fr_context_cat.name, 'Clients', "Did not found translation for initial value")
self.assertEqual(fr_context_cat.name, 'Clients (copie)', "Did not used default value for translated value")
if __name__ == '__main__':

View File

@ -1147,7 +1147,7 @@ class function(_column):
# make the result a tuple if it is not already one
if isinstance(value, (int,long)) and hasattr(obj._columns[field], 'relation'):
obj_model = obj.pool[obj._columns[field].relation]
dict_names = dict(obj_model.name_get(cr, uid, [value], context))
dict_names = dict(obj_model.name_get(cr, SUPERUSER_ID, [value], context))
result = (value, dict_names[value])
if field_type == 'binary':

View File

@ -5005,10 +5005,7 @@ class BaseModel(object):
else:
default['state'] = self._defaults['state']
context_wo_lang = context.copy()
if 'lang' in context:
del context_wo_lang['lang']
data = self.read(cr, uid, [id,], context=context_wo_lang)
data = self.read(cr, uid, [id,], context=context)
if data:
data = data[0]
else:
@ -5069,42 +5066,48 @@ class BaseModel(object):
fields = self.fields_get(cr, uid, context=context)
for field_name, field_def in fields.items():
# removing the lang to compare untranslated values
context_wo_lang = dict(context, lang=None)
old_record, new_record = self.browse(cr, uid, [old_id, new_id], context=context_wo_lang)
# we must recursively copy the translations for o2o and o2m
if field_def['type'] == 'one2many':
target_obj = self.pool[field_def['relation']]
old_record, new_record = self.read(cr, uid, [old_id, new_id], [field_name], context=context)
# here we rely on the order of the ids to match the translations
# as foreseen in copy_data()
old_children = sorted(old_record[field_name])
new_children = sorted(new_record[field_name])
old_children = sorted(r.id for r in old_record[field_name])
new_children = sorted(r.id for r in new_record[field_name])
for (old_child, new_child) in zip(old_children, new_children):
target_obj.copy_translations(cr, uid, old_child, new_child, context=context)
# and for translatable fields we keep them for copy
elif field_def.get('translate'):
if field_name in self._columns:
trans_name = self._name + "," + field_name
res_id = new_id
target_id = new_id
source_id = old_id
elif field_name in self._inherit_fields:
trans_name = self._inherit_fields[field_name][0] + "," + field_name
# get the id of the parent record to set the translation
inherit_field_name = self._inherit_fields[field_name][1]
res_id = self.read(cr, uid, [new_id], [inherit_field_name], context=context)[0][inherit_field_name][0]
target_id = new_record[inherit_field_name].id
source_id = old_record[inherit_field_name].id
else:
continue
trans_ids = trans_obj.search(cr, uid, [
('name', '=', trans_name),
('res_id', '=', old_id)
('res_id', '=', source_id)
])
records = trans_obj.read(cr, uid, trans_ids, context=context)
for record in records:
user_lang = context.get('lang')
for record in trans_obj.read(cr, uid, trans_ids, context=context):
del record['id']
# remove source to avoid triggering _set_src
del record['source']
record.update({'res_id': res_id})
record.update({'res_id': target_id})
if user_lang and user_lang == record['lang']:
# 'source' to force the call to _set_src
# 'value' needed if value is changed in copy(), want to see the new_value
record['source'] = old_record[field_name]
record['value'] = new_record[field_name]
trans_obj.create(cr, uid, record, context=context)

View File

@ -470,6 +470,7 @@ ALL_LANGUAGES = {
'ja_JP': u'Japanese / 日本語',
'ko_KP': u'Korean (KP) / 한국어 (KP)',
'ko_KR': u'Korean (KR) / 한국어 (KR)',
'lo_LA': u'Lao / ພາສາລາວ',
'lt_LT': u'Lithuanian / Lietuvių kalba',
'lv_LV': u'Latvian / latviešu valoda',
'ml_IN': u'Malayalam / മലയാളം',