Fix: Products, Categories, Sales, EndPoints
This commit is contained in:
parent
4f33143a36
commit
d745ee12e3
@ -1,4 +1,3 @@
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.wsgi import app
|
||||
from trytond.protocols.wrappers import (
|
||||
with_pool,
|
||||
@ -45,13 +44,32 @@ def parties(request, pool):
|
||||
@don_confiao_application
|
||||
def party(request, pool, party: int):
|
||||
Party = pool.get('party.party')
|
||||
with Transaction().set_context({'company': 1}):
|
||||
if request.method == 'GET':
|
||||
parties = Party.search_read([
|
||||
('id', '=', int(party))],
|
||||
order=[('id', 'ASC')],
|
||||
fields_names=['id', 'name'])
|
||||
return parties
|
||||
if request.method == 'GET':
|
||||
parties = Party.search_read([
|
||||
('id', '=', int(party))
|
||||
], order=[
|
||||
('id', 'ASC')
|
||||
], fields_names=[
|
||||
'id',
|
||||
'name'])
|
||||
return parties
|
||||
|
||||
|
||||
@app.route('/<database_name>/sale_don_confiao/categories', methods=['GET'])
|
||||
@allow_null_origin
|
||||
@with_pool
|
||||
@with_transaction()
|
||||
@don_confiao_application
|
||||
def categories(request, pool):
|
||||
Category = pool.get('product.category')
|
||||
categories = Category.search_read([
|
||||
], order=[
|
||||
('id', 'ASC')
|
||||
], fields_names=[
|
||||
'id',
|
||||
'name'
|
||||
])
|
||||
return categories
|
||||
|
||||
|
||||
@app.route('/<database_name>/sale_don_confiao/products', methods=['GET'])
|
||||
@ -61,10 +79,14 @@ def party(request, pool, party: int):
|
||||
@don_confiao_application
|
||||
def products(request, pool):
|
||||
Product = pool.get('product.product')
|
||||
products = Product.search_read(
|
||||
[],
|
||||
order=[('id', 'ASC')],
|
||||
fields_names=['id', 'name'])
|
||||
products = Product.search_read([
|
||||
('salable', '=', True)
|
||||
], order=[
|
||||
('id', 'ASC')
|
||||
], fields_names=[
|
||||
'id',
|
||||
'name'
|
||||
])
|
||||
return products
|
||||
|
||||
|
||||
@ -76,17 +98,42 @@ def products(request, pool):
|
||||
@with_transaction()
|
||||
@don_confiao_application
|
||||
def search_products(request, pool, product_name: str):
|
||||
with Transaction().set_context({'company': 1}):
|
||||
Product = pool.get('product.product')
|
||||
products = Product.search_read(
|
||||
[('name', 'ilike', f'%{product_name}%')],
|
||||
order=[('id', 'ASC')],
|
||||
fields_names=[
|
||||
'id', 'name', 'list_price',
|
||||
'description'
|
||||
])
|
||||
Product = pool.get('product.product')
|
||||
products = Product.search_read([
|
||||
('name', 'ilike', f'%{product_name}%')
|
||||
], order=[
|
||||
('id', 'ASC')
|
||||
], fields_names=[
|
||||
'id',
|
||||
'name',
|
||||
'list_price',
|
||||
'description'
|
||||
])
|
||||
|
||||
return products
|
||||
return products
|
||||
|
||||
|
||||
@app.route('/<database_name>/sale_don_confiao/sale/<sale_id>', methods=['GET'])
|
||||
@allow_null_origin
|
||||
@with_pool
|
||||
@with_transaction()
|
||||
@don_confiao_application
|
||||
def sale(request, pool, sale_id: int):
|
||||
Sale = pool.get('sale.sale')
|
||||
sales = Sale.search_read([
|
||||
('id', '=', sale_id)
|
||||
], order=[
|
||||
('id', 'ASC')
|
||||
], fields_names=[
|
||||
'id',
|
||||
'party.name',
|
||||
'sale_date',
|
||||
'shipment_address.street',
|
||||
'untaxed_amount_cache',
|
||||
'tax_amount_cache',
|
||||
'total_amount_cache',
|
||||
])
|
||||
return sales
|
||||
|
||||
|
||||
@app.route('/<database_name>/sale_don_confiao/sales', methods=['GET'])
|
||||
@ -95,12 +142,17 @@ def search_products(request, pool, product_name: str):
|
||||
@with_transaction()
|
||||
@don_confiao_application
|
||||
def sales(request, pool):
|
||||
with Transaction().set_context(
|
||||
{'company': 1}):
|
||||
Sale = pool.get('sale.sale')
|
||||
sales = Sale.search_read([
|
||||
], order=[
|
||||
('id', 'ASC')
|
||||
], fields_names=['id', 'party.name'])
|
||||
|
||||
return sales
|
||||
Sale = pool.get('sale.sale')
|
||||
sales = Sale.search_read([
|
||||
], order=[
|
||||
('id', 'ASC')
|
||||
], fields_names=[
|
||||
'id',
|
||||
'party.name',
|
||||
'sale_date',
|
||||
'shipment_address.street',
|
||||
'untaxed_amount_cache',
|
||||
'tax_amount_cache',
|
||||
'total_amount_cache',
|
||||
])
|
||||
return sales
|
||||
|
@ -83,6 +83,16 @@ class DonConfiaoApiRouteTestCase(
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
self.assertEqual(len(parties), 2)
|
||||
|
||||
def test_get_categories(self):
|
||||
client = self.client()
|
||||
response = client.get(
|
||||
f'/{self.db_name}/sale_don_confiao/categories',
|
||||
headers={
|
||||
'Authorization': f'bearer {self.key}',
|
||||
})
|
||||
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
|
||||
def test_get_products(self):
|
||||
pool = Pool(DB_NAME)
|
||||
transaction = Transaction().start(DB_NAME, 0, _lock_tables=[
|
||||
@ -101,6 +111,8 @@ class DonConfiaoApiRouteTestCase(
|
||||
template, = ProductTemplate.create([{
|
||||
'name': 'Product',
|
||||
'default_uom': Uom.search([('name', '=', 'Unit')])[0].id,
|
||||
'sale_uom': Uom.search([('name', '=', 'Unit')])[0].id,
|
||||
'salable': True
|
||||
}])
|
||||
|
||||
Product.create([{'template': template.id}])
|
||||
|
Loading…
Reference in New Issue
Block a user