159 lines
3.6 KiB
Python
159 lines
3.6 KiB
Python
from trytond.wsgi import app
|
|
from trytond.protocols.wrappers import (
|
|
with_pool,
|
|
with_transaction,
|
|
user_application,
|
|
allow_null_origin)
|
|
import json
|
|
|
|
don_confiao_application = user_application(
|
|
'sale_don_confiao')
|
|
|
|
|
|
@app.route('/<database_name>/sale_don_confiao/parties', methods=[
|
|
'GET', 'POST'])
|
|
@allow_null_origin
|
|
@with_pool
|
|
@with_transaction()
|
|
@don_confiao_application
|
|
def parties(request, pool):
|
|
Party = pool.get('party.party')
|
|
if request.method == 'GET':
|
|
parties = Party.search_read(
|
|
[],
|
|
order=[('id', 'ASC')],
|
|
fields_names=['id', 'name'])
|
|
return parties
|
|
|
|
if request.method == 'POST':
|
|
data = json.loads(
|
|
request.get_data().decode()
|
|
)
|
|
|
|
party = Party()
|
|
party.name = data['name']
|
|
party.save()
|
|
|
|
|
|
@app.route(
|
|
'/<database_name>/sale_don_confiao/party/<party>',
|
|
methods=['GET'])
|
|
@allow_null_origin
|
|
@with_pool
|
|
@with_transaction()
|
|
@don_confiao_application
|
|
def party(request, pool, party: int):
|
|
Party = pool.get('party.party')
|
|
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'])
|
|
@allow_null_origin
|
|
@with_pool
|
|
@with_transaction()
|
|
@don_confiao_application
|
|
def products(request, pool):
|
|
Product = pool.get('product.product')
|
|
products = Product.search_read([
|
|
('salable', '=', True)
|
|
], order=[
|
|
('id', 'ASC')
|
|
], fields_names=[
|
|
'id',
|
|
'name'
|
|
])
|
|
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: str):
|
|
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
|
|
|
|
|
|
@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'])
|
|
@allow_null_origin
|
|
@with_pool
|
|
@with_transaction()
|
|
@don_confiao_application
|
|
def sales(request, pool):
|
|
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
|