[FIX]stock: improve a name_serch method for name and prefix
authorMayur Maheshwari (OpenERP) <mma@tinyerp.com>
Fri, 16 Dec 2011 06:10:09 +0000 (11:40 +0530)
committerMayur Maheshwari (OpenERP) <mma@tinyerp.com>
Fri, 16 Dec 2011 06:10:09 +0000 (11:40 +0530)
bzr revid: mma@tinyerp.com-20111216061009-8g3oo2u190empr5u

addons/stock/stock.py

index adb04b9..cca6361 100644 (file)
@@ -1361,10 +1361,16 @@ class stock_production_lot(osv.osv):
             res.append((record['id'], name))
         return res
     
-    def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100):
-        ids = self.search(cr, user, [('prefix',operator,name)]+ args, limit=limit, context=context)
-        result = self.name_get(cr, user, ids, context=context)
-        return result
+    def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
+        args = args or []
+        ids = []
+        if name:
+            ids = self.search(cr, uid, [('prefix', operator, name)] + args, limit=limit, context=context or {})
+            if not ids:
+                ids = self.search(cr, uid, [('name', operator, name)] + args, limit=limit, context=context or {})
+        else:
+            ids = self.search(cr, uid, args, limit=limit, context=context or {})
+        return self.name_get(cr, uid, ids, context or {})
 
     _name = 'stock.production.lot'
     _description = 'Production lot'