Reviewers: ,


Please review this at http://codereview.tryton.org/585007/

Affected files:
  M trytond/model/fields/one2many.py


Index: trytond/model/fields/one2many.py
===================================================================

--- a/trytond/model/fields/one2many.py
+++ b/trytond/model/fields/one2many.py
@@ -86,7 +86,8 @@
         res = {}
         for i in ids:
             res[i] = []
-        ids2 = []
+
+        targets = []
         for i in range(0, len(ids), Transaction().cursor.IN_MAX):
             sub_ids = ids[i:i + Transaction().cursor.IN_MAX]
             if field._type == 'reference':
@@ -94,37 +95,13 @@
                 clause = [(self.field, 'in', references)]
             else:
                 clause = [(self.field, 'in', sub_ids)]
- ids2.append(map(int, Relation.search(clause, order=self.order)))
+            targets.append(Relation.search(clause, order=self.order))
+        targets = list(chain(*targets))

-        cache = Transaction().cursor.get_cache(Transaction().context)
-        cache.setdefault(self.model_name, {})
-        ids3 = []
-        for i in chain(*ids2):
-            if i in cache[self.model_name] \
-                    and self.field in cache[self.model_name][i]:
-                if field._type == 'reference':
- _, id_ = cache[self.model_name][i][self.field].split(',')
-                    id_ = int(id_)
-                else:
-                    id_ = cache[self.model_name][i][self.field]
-                res[id_].append(i)
-            else:
-                ids3.append(i)
-
-        if ids3:
-            for i in Relation.read(ids3, [self.field]):
-                if field._type == 'reference':
-                    _, id_ = i[self.field].split(',')
-                    id_ = int(id_)
-                else:
-                    id_ = i[self.field]
-                res[id_].append(i['id'])
-
-        index_of_ids2 = dict((i, index)
-            for index, i in enumerate(chain(*ids2)))
-        for id_, val in res.iteritems():
-            res[id_] = tuple(sorted(val, key=lambda x: index_of_ids2[x]))
-        return res
+        for target in targets:
+            origin_id = getattr(target, self.field).id
+            res[origin_id].append(target.id)
+        return dict((key, tuple(value)) for key, value in res.iteritems())

     def set(self, ids, model, name, values):
         '''



--
--
[email protected] mailing list



Reply via email to