[IMP] stock: add 'name_search' by barcode in stock.location

Closes #12043
This commit is contained in:
Moisés López
2017-06-23 14:53:34 +02:00
committed by Martin Trigaux
parent 0aea445e3e
commit 4a3699bea9
4 changed files with 41 additions and 0 deletions
+1
View File
@@ -13,6 +13,7 @@
<field name="name">IT Vendors</field>
<field name="location_id" ref="stock_location_suppliers"/>
<field name="usage">supplier</field>
<field name="barcode">2601985</field>
</record>
<record id="stock_location_4" model="stock.location">
<field name="name">Big Vendors</field>
+8
View File
@@ -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
+1
View File
@@ -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
@@ -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)