diff --git a/addons/stock/data/stock_demo.xml b/addons/stock/data/stock_demo.xml
index c00f0d9bb89..8d32f68dd99 100644
--- a/addons/stock/data/stock_demo.xml
+++ b/addons/stock/data/stock_demo.xml
@@ -13,6 +13,7 @@
IT Vendors
supplier
+ 2601985
Big Vendors
diff --git a/addons/stock/models/stock_location.py b/addons/stock/models/stock_location.py
index 540bd6f1a06..62c447360f4 100644
--- a/addons/stock/models/stock_location.py
+++ b/addons/stock/models/stock_location.py
@@ -91,6 +91,14 @@ class Location(models.Model):
ret_list.append((orig_location.id, name))
return ret_list
+ @api.model
+ def name_search(self, name, args=None, operator='ilike', limit=100):
+ """ search full name and barcode """
+ if args is None:
+ args = []
+ recs = self.search(['|', ('barcode', operator, name), ('complete_name', operator, name)] + args, limit=limit)
+ return recs.name_get()
+
def get_putaway_strategy(self, product):
''' Returns the location where the product has to be put, if any compliant putaway strategy is found. Otherwise returns None.'''
current_location = self
diff --git a/addons/stock/tests/__init__.py b/addons/stock/tests/__init__.py
index 1878c99baac..92b1e412f45 100644
--- a/addons/stock/tests/__init__.py
+++ b/addons/stock/tests/__init__.py
@@ -4,3 +4,4 @@ from . import test_stock_flow
from . import test_product
from . import test_warehouse
from . import test_shipment
+from . import test_stock_location_search
diff --git a/addons/stock/tests/test_stock_location_search.py b/addons/stock/tests/test_stock_location_search.py
new file mode 100644
index 00000000000..014759c7899
--- /dev/null
+++ b/addons/stock/tests/test_stock_location_search.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+
+from odoo.tests import common
+
+
+class TestStockLocationSearch(common.TransactionCase):
+ def setUp(self):
+ super(TestStockLocationSearch, self).setUp()
+ self.location = self.env['stock.location']
+ self.location_barcode = self.env.ref('stock.stock_location_3')
+ self.location_barcode_id = self.location_barcode.id
+ self.barcode = self.location_barcode.barcode
+ self.name = self.location_barcode.name
+
+ def test_10_location_search_by_barcode(self):
+ """Search stock location by barcode"""
+ location_names = self.location.name_search(name=self.barcode)
+ self.assertEquals(len(location_names), 1)
+ location_id_found = location_names[0][0]
+ self.assertEquals(self.location_barcode_id, location_id_found)
+
+ def test_20_location_search_by_name(self):
+ """Search stock location by name"""
+ location_names = self.location.name_search(name=self.name)
+ location_ids_found = [location_name[0] for location_name in location_names]
+ self.assertTrue(self.location_barcode_id in location_ids_found)
+
+ def test_30_location_search_wo_results(self):
+ """Search stock location without results"""
+ location_names = self.location.name_search(name='nonexistent')
+ self.assertFalse(location_names)