Feat: GET search_products by name
This commit is contained in:
parent
00c7052838
commit
04d76ee7d9
@ -67,6 +67,21 @@ def products(request, pool):
|
|||||||
return products
|
return products
|
||||||
|
|
||||||
|
|
||||||
|
@app.route(
|
||||||
|
'/<database_name>/sale_don_confiao/search_products/<product_name>',
|
||||||
|
methods=['GET'])
|
||||||
|
@allow_null_origin
|
||||||
|
@with_pool
|
||||||
|
@with_transaction()
|
||||||
|
@don_confiao_application
|
||||||
|
def search_products(request, pool, product_name):
|
||||||
|
Product = pool.get('product.product')
|
||||||
|
products = Product.search_read(
|
||||||
|
[('name', 'like', product_name)],
|
||||||
|
order=[('id', 'ASC')],
|
||||||
|
fields_names=['id', 'name', 'list_price'])
|
||||||
|
return products
|
||||||
|
|
||||||
@app.route('/<database_name>/sale_don_confiao/sales', methods=['GET'])
|
@app.route('/<database_name>/sale_don_confiao/sales', methods=['GET'])
|
||||||
@allow_null_origin
|
@allow_null_origin
|
||||||
@with_pool
|
@with_pool
|
||||||
|
@ -98,11 +98,11 @@ class DonConfiaoApiRouteTestCase(
|
|||||||
ProductTemplate = pool.get('product.template')
|
ProductTemplate = pool.get('product.template')
|
||||||
Product = pool.get('product.product')
|
Product = pool.get('product.product')
|
||||||
Uom = pool.get('product.uom')
|
Uom = pool.get('product.uom')
|
||||||
template, = ProductTemplate.create([
|
template, = ProductTemplate.create([{
|
||||||
{'name': 'Product',
|
'name': 'Product',
|
||||||
'default_uom': Uom.search([('name', '=', 'Unit')])[0].id
|
'default_uom': Uom.search([('name', '=', 'Unit')])[0].id,
|
||||||
}
|
'list_price': 5000
|
||||||
])
|
}])
|
||||||
|
|
||||||
Product.create([{'template': template.id}])
|
Product.create([{'template': template.id}])
|
||||||
|
|
||||||
@ -118,6 +118,20 @@ class DonConfiaoApiRouteTestCase(
|
|||||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||||
self.assertEqual(len(products), 1)
|
self.assertEqual(len(products), 1)
|
||||||
|
|
||||||
|
def test_search_products(self):
|
||||||
|
client = self.client()
|
||||||
|
response = client.get(
|
||||||
|
f'/{self.db_name}/sale_don_confiao/search_products/product',
|
||||||
|
headers={
|
||||||
|
'Authorization': f'bearer {self.key}',
|
||||||
|
})
|
||||||
|
|
||||||
|
products = json.loads(
|
||||||
|
response.get_data().decode())
|
||||||
|
|
||||||
|
raise Exception(products)
|
||||||
|
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||||
|
|
||||||
def test_get_sales(self):
|
def test_get_sales(self):
|
||||||
pool = Pool(DB_NAME)
|
pool = Pool(DB_NAME)
|
||||||
transaction = Transaction().start(DB_NAME, user=0, _lock_tables=[
|
transaction = Transaction().start(DB_NAME, user=0, _lock_tables=[
|
||||||
|
Loading…
Reference in New Issue
Block a user