diff --git a/openerp/addons/base/tests/test_base.py b/openerp/addons/base/tests/test_base.py index a7df2a5bb27..1ca66f57943 100644 --- a/openerp/addons/base/tests/test_base.py +++ b/openerp/addons/base/tests/test_base.py @@ -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__': diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py index 99bce504414..c9509a1e4b9 100644 --- a/openerp/osv/fields.py +++ b/openerp/osv/fields.py @@ -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': diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index 212eb033f84..d0504300431 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -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) diff --git a/openerp/tools/misc.py b/openerp/tools/misc.py index 65e7c38e536..ea5bf6a185b 100644 --- a/openerp/tools/misc.py +++ b/openerp/tools/misc.py @@ -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 / മലയാളം',