Yogesh(Open ERP) has proposed merging 
lp:~openerp-dev/openobject-server/trunk-bug-705364-ysa into 
lp:openobject-server.

Requested reviews:
  Naresh(OpenERP) (nch-openerp)
Related bugs:
  Bug #705364 in OpenERP Server: "[6.0][5.0] ORM bug : function field with type 
one2many = "ir_translation polluted and duplicated function dead""
  https://bugs.launchpad.net/openobject-server/+bug/705364

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-bug-705364-ysa/+merge/64526
-- 
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-bug-705364-ysa/+merge/64526
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-server/trunk-bug-705364-ysa.
=== modified file 'openerp/osv/orm.py'
--- openerp/osv/orm.py	2011-06-10 17:31:30 +0000
+++ openerp/osv/orm.py	2011-06-14 10:31:19 +0000
@@ -4361,7 +4361,7 @@
         trans_obj = self.pool.get('ir.translation')
         fields = self.fields_get(cr, uid, context=context)
 
-        translation_records = []
+        translation_names = []
         for field_name, field_def in fields.items():
             # we must recursively copy the translations for o2o and o2m
             if field_def['type'] in ('one2one', 'one2many'):
@@ -4381,16 +4381,33 @@
                 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))
-
-        for record in translation_records:
-            del record['id']
-            record['res_id'] = new_id
-            trans_obj.create(cr, uid, record, context=context)
+                    translation_names.append(trans_name)
+
+        if translation_names:
+            # first, find all ids of translations that already exist
+            trans_exist_ids = trans_obj.search(cr, uid, [
+                    ('name', 'in', translation_names),
+                    ('res_id', '=', new_id)
+                ])
+            if trans_exist_ids:
+                # Remove from the list the names that are already translated
+                for res in trans_obj.read(cr,uid, trans_exist_ids, ['name'], context=context):
+                    if res['name'] in translation_names:
+                        translation_names.remove(res['name'])
+
+            trans_ids = []
+            if translation_names:
+                # then, locate the ones that we need to copy
+                trans_ids = trans_obj.search(cr, uid, [
+                        ('name', 'in', translation_names),
+                        ('res_id', '=', old_id)
+                ])
+
+            if trans_ids:
+                for record in trans_obj.read(cr, uid, trans_ids, context=context):
+                    del record['id']
+                    record['res_id'] = new_id
+                    trans_obj.create(cr, uid, record, context=context)
 
 
     def copy(self, cr, uid, id, default=None, context=None):

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to