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.wsgi import app
|
||||||
from trytond.protocols.wrappers import (
|
from trytond.protocols.wrappers import (
|
||||||
with_pool,
|
with_pool,
|
||||||
@ -45,13 +44,32 @@ def parties(request, pool):
|
|||||||
@don_confiao_application
|
@don_confiao_application
|
||||||
def party(request, pool, party: int):
|
def party(request, pool, party: int):
|
||||||
Party = pool.get('party.party')
|
Party = pool.get('party.party')
|
||||||
with Transaction().set_context({'company': 1}):
|
if request.method == 'GET':
|
||||||
if request.method == 'GET':
|
parties = Party.search_read([
|
||||||
parties = Party.search_read([
|
('id', '=', int(party))
|
||||||
('id', '=', int(party))],
|
], order=[
|
||||||
order=[('id', 'ASC')],
|
('id', 'ASC')
|
||||||
fields_names=['id', 'name'])
|
], fields_names=[
|
||||||
return parties
|
'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'])
|
@app.route('/<database_name>/sale_don_confiao/products', methods=['GET'])
|
||||||
@ -61,10 +79,14 @@ def party(request, pool, party: int):
|
|||||||
@don_confiao_application
|
@don_confiao_application
|
||||||
def products(request, pool):
|
def products(request, pool):
|
||||||
Product = pool.get('product.product')
|
Product = pool.get('product.product')
|
||||||
products = Product.search_read(
|
products = Product.search_read([
|
||||||
[],
|
('salable', '=', True)
|
||||||
order=[('id', 'ASC')],
|
], order=[
|
||||||
fields_names=['id', 'name'])
|
('id', 'ASC')
|
||||||
|
], fields_names=[
|
||||||
|
'id',
|
||||||
|
'name'
|
||||||
|
])
|
||||||
return products
|
return products
|
||||||
|
|
||||||
|
|
||||||
@ -76,17 +98,42 @@ def products(request, pool):
|
|||||||
@with_transaction()
|
@with_transaction()
|
||||||
@don_confiao_application
|
@don_confiao_application
|
||||||
def search_products(request, pool, product_name: str):
|
def search_products(request, pool, product_name: str):
|
||||||
with Transaction().set_context({'company': 1}):
|
Product = pool.get('product.product')
|
||||||
Product = pool.get('product.product')
|
products = Product.search_read([
|
||||||
products = Product.search_read(
|
('name', 'ilike', f'%{product_name}%')
|
||||||
[('name', 'ilike', f'%{product_name}%')],
|
], order=[
|
||||||
order=[('id', 'ASC')],
|
('id', 'ASC')
|
||||||
fields_names=[
|
], fields_names=[
|
||||||
'id', 'name', 'list_price',
|
'id',
|
||||||
'description'
|
'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'])
|
@app.route('/<database_name>/sale_don_confiao/sales', methods=['GET'])
|
||||||
@ -95,12 +142,17 @@ def search_products(request, pool, product_name: str):
|
|||||||
@with_transaction()
|
@with_transaction()
|
||||||
@don_confiao_application
|
@don_confiao_application
|
||||||
def sales(request, pool):
|
def sales(request, pool):
|
||||||
with Transaction().set_context(
|
Sale = pool.get('sale.sale')
|
||||||
{'company': 1}):
|
sales = Sale.search_read([
|
||||||
Sale = pool.get('sale.sale')
|
], order=[
|
||||||
sales = Sale.search_read([
|
('id', 'ASC')
|
||||||
], order=[
|
], fields_names=[
|
||||||
('id', 'ASC')
|
'id',
|
||||||
], fields_names=['id', 'party.name'])
|
'party.name',
|
||||||
|
'sale_date',
|
||||||
return sales
|
'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(response.status_code, HTTPStatus.OK)
|
||||||
self.assertEqual(len(parties), 2)
|
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):
|
def test_get_products(self):
|
||||||
pool = Pool(DB_NAME)
|
pool = Pool(DB_NAME)
|
||||||
transaction = Transaction().start(DB_NAME, 0, _lock_tables=[
|
transaction = Transaction().start(DB_NAME, 0, _lock_tables=[
|
||||||
@ -101,6 +111,8 @@ class DonConfiaoApiRouteTestCase(
|
|||||||
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,
|
||||||
|
'sale_uom': Uom.search([('name', '=', 'Unit')])[0].id,
|
||||||
|
'salable': True
|
||||||
}])
|
}])
|
||||||
|
|
||||||
Product.create([{'template': template.id}])
|
Product.create([{'template': template.id}])
|
||||||
|
Loading…
Reference in New Issue
Block a user