Divyesh Makwana(OpenERP) has proposed merging 
lp:~openerp-dev/openobject-server/trunk-bug-799655-mdi into 
lp:openobject-server.

Requested reviews:
  Naresh(OpenERP) (nch-openerp)
Related bugs:
  Bug #799655 in OpenERP Server: "[PS] Wrong data taken when duplicating a 
product"
  https://bugs.launchpad.net/openobject-server/+bug/799655

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-bug-799655-mdi/+merge/78547

Fixed Wrong data taken when duplicating a product
-- 
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-bug-799655-mdi/+merge/78547
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-server/trunk-bug-799655-mdi.
=== modified file 'openerp/osv/orm.py'
--- openerp/osv/orm.py	2011-10-06 14:27:27 +0000
+++ openerp/osv/orm.py	2011-10-07 07:40:28 +0000
@@ -55,6 +55,7 @@
 import types
 import warnings
 from lxml import etree
+import difflib
 
 import fields
 import openerp
@@ -1814,7 +1815,7 @@
     def _get_default_calendar_view(self, cr, user, context=None):
         """ Generates a default calendar view by trying to infer
         calendar fields from a number of pre-set attribute names
-        
+
         :param cr: database cursor
         :param int user: user id
         :param dict context: connection context
@@ -2238,7 +2239,7 @@
                                 or ``'='``.
            :param int limit: optional max number of records to return
            :rtype: list
-           :return: list of pairs ``(id,text_repr)`` for all matching records. 
+           :return: list of pairs ``(id,text_repr)`` for all matching records.
         """
         return self._name_search(cr, user, name, args, operator, context, limit)
 
@@ -4552,8 +4553,9 @@
         # 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 = []
+        data = {}
         for field_name, field_def in fields.items():
+            str = ''
             # we must recursively copy the translations for o2o and o2m
             if field_def['type'] in ('one2one', 'one2many'):
                 target_obj = self.pool.get(field_def['relation'])
@@ -4572,16 +4574,35 @@
                 elif field_name in self._inherit_fields:
                     trans_name = self._inherit_fields[field_name][0] + "," + field_name
                 if trans_name:
+                    obj, obj_field = trans_name.split(',')
+                    obj_get_name_new = self.pool.get(obj).read(cr, uid, new_id, [obj_field])
+                    obj_get_name_old = self.pool.get(obj).read(cr, uid, old_id, [obj_field])
+                    trans_id = trans_obj.search(cr, uid, [('src', '=', obj_get_name_new[obj_field])])
+
+                    if not trans_id:
+                        s1 = obj_get_name_new[obj_field]
+                        s2 = obj_get_name_old[obj_field]
+                        if s1 and s2:
+                            s = difflib.SequenceMatcher(s1, s2)
+                            for block in s.get_matching_blocks():
+                                str = s1[block[0]:]
+
                     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)
+
+                    data = trans_obj.read(cr, uid, trans_ids, context=context)
+                    if len(data) > 0:
+                        data = data[0]
+                    else:
+                        data = {}
+
+                    if data.has_key('id'):
+                        del data['id']
+                        data['value'] = data['value'] + str
+                        data['res_id'] = new_id
+                        trans_obj.create(cr, uid, data, context=context)
 
 
     def copy(self, cr, uid, id, default=None, context=None):
@@ -4695,7 +4716,7 @@
 
         :return: map of ids to their fully qualified XML ID,
                  defaulting to an empty string when there's none
-                 (to be usable as a function field), 
+                 (to be usable as a function field),
                  e.g.::
 
                      { 'id': 'module.ext_id',
@@ -4784,7 +4805,7 @@
 class TransientModel(BaseModel):
     """Model super-class for transient records, meant to be temporarily
        persisted, and regularly vaccuum-cleaned.
- 
+
        A TransientModel has a simplified access rights management,
        all users can create new records, and may only access the
        records they created. The super-user has unrestricted access

_______________________________________________
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