[FIX] osv: corrected _search() of osv_memory object which was returning wrong result...
authorQuentin THEURET <qt@tempo-consulting.fr>
Thu, 17 Nov 2011 06:07:04 +0000 (11:37 +0530)
committerRifakat (OpenERP) <rha@tinyerp.com>
Thu, 17 Nov 2011 06:07:04 +0000 (11:37 +0530)
bzr revid: rha@tinyerp.com-20111117060704-f5q4i5bn2ae11g18

bin/osv/orm.py

index 62c8439..0f4b455 100644 (file)
@@ -2058,14 +2058,17 @@ class orm_memory(orm_template):
             return self.datas.keys()
 
         res = []
-        counter = 0
+        counter = 1
         #Find the value of dict
         f = False
         if result:
             for id, data in self.datas.items():
-                counter = counter + 1
                 data['id'] = id
-                if limit and (counter > int(limit)):
+                # If no offset, give the first entries between 0 and the limit
+                if not offset and limit and (counter > int(limit)):
+                    break
+                # If offset, give only entries between offset and the offset+limit
+                elif offset and limit and (counter > int(limit + offset)):
                     break
                 f = True
                 for arg in result:
@@ -2075,11 +2078,11 @@ class orm_memory(orm_template):
                         val = eval('data[arg[0]]'+arg[1] +' arg[2]', locals())
                     elif arg[1] in ['ilike']:
                         val = (str(data[arg[0]]).find(str(arg[2]))!=-1)
-
                     f = f and val
-
                 if f:
-                    res.append(id)
+                    if counter > offset:
+                        res.append(id)
+                    counter += 1
         if count:
             return len(res)
         return res or []