[FIX] orm: when duplicating a record, if duplicates translations on a field from _inherits model, use the id of the parent record instead.
Avoid getting old value by removing 'source' value from read result. lp bug: https://launchpad.net/bugs/1237878 fixed bzr revid: mat@openerp.com-20131104163729-te0p9863g9ydt282
This commit is contained in:
commit
02fd46e8d4
|
@ -304,5 +304,47 @@ class test_partner_recursion(common.TransactionCase):
|
|||
cr, uid, p1, p2, p3 = self.cr, self.uid, self.p1, self.p2, self.p3
|
||||
self.assertTrue(self.res_partner.write(cr, uid, [p1,p2,p3], {'phone': '123456'}))
|
||||
|
||||
class test_translation(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(test_translation, self).setUp()
|
||||
self.res_category = self.registry('res.partner.category')
|
||||
self.ir_translation = self.registry('ir.translation')
|
||||
cr, uid = self.cr, self.uid
|
||||
self.registry('ir.translation').load(cr, ['base'], ['fr_BE'])
|
||||
self.cat_id = self.res_category.create(cr, uid, {'name': 'Customers'})
|
||||
self.ir_translation.create(cr, uid, {'name': 'res.partner.category,name', 'module':'base',
|
||||
'value': 'Clients', 'res_id': self.cat_id, 'lang':'fr_BE', 'state':'translated', 'type': 'model'})
|
||||
|
||||
def test_101_create_translated_record(self):
|
||||
cr, uid = self.cr, self.uid
|
||||
|
||||
no_context_cat = self.res_category.browse(cr, uid, self.cat_id)
|
||||
self.assertEqual(no_context_cat.name, 'Customers', "Error in basic name_get")
|
||||
|
||||
fr_context_cat = self.res_category.browse(cr, uid, self.cat_id, context={'lang':'fr_BE'})
|
||||
self.assertEqual(fr_context_cat.name, 'Clients', "Translation not found")
|
||||
|
||||
def test_102_duplicate_record(self):
|
||||
cr, uid = self.cr, self.uid
|
||||
self.new_cat_id = self.res_category.copy(cr, uid, self.cat_id, context={'lang':'fr_BE'})
|
||||
|
||||
no_context_cat = self.res_category.browse(cr, uid, self.new_cat_id)
|
||||
self.assertEqual(no_context_cat.name, 'Customers', "Duplication did not set untranslated value")
|
||||
|
||||
fr_context_cat = self.res_category.browse(cr, uid, self.new_cat_id, context={'lang':'fr_BE'})
|
||||
self.assertEqual(fr_context_cat.name, 'Clients', "Did not found translation for initial value")
|
||||
|
||||
def test_103_duplicate_record_fr(self):
|
||||
cr, uid = self.cr, self.uid
|
||||
self.new_fr_cat_id = self.res_category.copy(cr, uid, self.cat_id, default={'name': 'Clients (copie)'}, context={'lang':'fr_BE'})
|
||||
|
||||
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")
|
||||
|
||||
fr_context_cat = self.res_category.browse(cr, uid, self.new_fr_cat_id, context={'lang':'fr_BE'})
|
||||
self.assertEqual(fr_context_cat.name, 'Clients', "Did not found translation for initial value")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest2.main()
|
||||
|
|
|
@ -4985,7 +4985,6 @@ class BaseModel(object):
|
|||
# TODO it seems fields_get can be replaced by _all_columns (no need for translation)
|
||||
fields = self.fields_get(cr, uid, context=context)
|
||||
|
||||
translation_records = []
|
||||
for field_name, field_def in fields.items():
|
||||
# we must recursively copy the translations for o2o and o2m
|
||||
if field_def['type'] == 'one2many':
|
||||
|
@ -4999,22 +4998,31 @@ class BaseModel(object):
|
|||
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'):
|
||||
trans_name = ''
|
||||
|
||||
if field_name in self._columns:
|
||||
trans_name = self._name + "," + field_name
|
||||
res_id = new_id
|
||||
|
||||
elif field_name in self._inherit_fields:
|
||||
trans_name = self._inherit_fields[field_name][0] + "," + field_name
|
||||
if trans_name:
|
||||
trans_ids = trans_obj.search(cr, uid, [
|
||||
('name', '=', trans_name),
|
||||
('res_id', '=', old_id)
|
||||
])
|
||||
translation_records.extend(trans_obj.read(cr, uid, trans_ids, context=context))
|
||||
# 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]
|
||||
|
||||
for record in translation_records:
|
||||
del record['id']
|
||||
record['res_id'] = new_id
|
||||
trans_obj.create(cr, uid, record, context=context)
|
||||
else:
|
||||
continue
|
||||
|
||||
trans_ids = trans_obj.search(cr, uid, [
|
||||
('name', '=', trans_name),
|
||||
('res_id', '=', old_id)
|
||||
])
|
||||
records = trans_obj.read(cr, uid, trans_ids, context=context)
|
||||
for record in records:
|
||||
del record['id']
|
||||
# remove source to avoid triggering _set_src
|
||||
del record['source']
|
||||
record.update({'res_id': res_id})
|
||||
trans_obj.create(cr, uid, record, context=context)
|
||||
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
|
|
Loading…
Reference in New Issue