return party created info

This commit is contained in:
Mongar28 2025-03-22 18:30:35 -05:00
parent 1e035153dc
commit bdbeb4d4cf

View File

@ -4,163 +4,161 @@ from trytond.protocols.wrappers import (
with_pool, with_pool,
with_transaction, with_transaction,
user_application, user_application,
allow_null_origin) allow_null_origin,
)
import json import json
don_confiao_application = user_application( don_confiao_application = user_application("sale_don_confiao")
'sale_don_confiao')
@app.route('/<database_name>/sale_don_confiao/parties', methods=[ @app.route("/<database_name>/sale_don_confiao/parties", methods=["GET", "POST"])
'GET', 'POST'])
@allow_null_origin @allow_null_origin
@with_pool @with_pool
@with_transaction() @with_transaction()
@don_confiao_application @don_confiao_application
def parties(request, pool): def parties(request, pool):
Party = pool.get('party.party') Party = pool.get("party.party")
if request.method == 'GET': if request.method == "GET":
parties = Party.search_read( parties = Party.search_read(
[], [], order=[("id", "ASC")], fields_names=["id", "name"]
order=[('id', 'ASC')], )
fields_names=['id', 'name'])
return parties return parties
if request.method == 'POST': if request.method == "POST":
data = json.loads( data = json.loads(request.get_data().decode())
request.get_data().decode()
)
Party.create([dict(data)]) party = Party.create([dict(data)])
if party:
party = party[0].id
response_data = {
"id": party,
"status": "success",
"message": "Party created successfully",
}
return json.dumps(response_data), 201
response_data = {
"id": None,
"status": "success",
"message": "Party not created",
}
return json.dumps(response_data), 404
@app.route( @app.route("/<database_name>/sale_don_confiao/party/<party>", methods=["GET"])
'/<database_name>/sale_don_confiao/party/<party>',
methods=['GET'])
@allow_null_origin @allow_null_origin
@with_pool @with_pool
@with_transaction() @with_transaction()
@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")
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=[ )
'id',
'name'])
return parties return parties
@app.route('/<database_name>/sale_don_confiao/categories', methods=['GET']) @app.route("/<database_name>/sale_don_confiao/categories", methods=["GET"])
@allow_null_origin @allow_null_origin
@with_pool @with_pool
@with_transaction() @with_transaction()
@don_confiao_application @don_confiao_application
def categories(request, pool): def categories(request, pool):
Category = pool.get('product.category') Category = pool.get("product.category")
categories = Category.search_read([ categories = Category.search_read(
], order=[ [], order=[("id", "ASC")], fields_names=["id", "name"]
('id', 'ASC') )
], fields_names=[
'id',
'name'
])
return categories return categories
@app.route('/<database_name>/sale_don_confiao/products', methods=['GET']) @app.route("/<database_name>/sale_don_confiao/products", methods=["GET"])
@allow_null_origin @allow_null_origin
@with_pool @with_pool
@with_transaction() @with_transaction()
@don_confiao_application @don_confiao_application
def products(request, pool): def products(request, pool):
with Transaction().set_context( with Transaction().set_context({"company": 1, "locations": [3]}):
{'company': 1, 'locations': [3]}): Product = pool.get("product.product")
Product = pool.get('product.product') products = Product.search_read(
products = Product.search_read([ [("salable", "=", True)],
('salable', '=', True) order=[("id", "ASC")],
], order=[ fields_names=[
('id', 'ASC') "id",
], fields_names=[ "name",
'id', "template.list_price",
'name', "default_uom.name",
'template.list_price', "description",
'default_uom.name', "quantity",
'description', ],
'quantity', )
])
return products return products
@app.route( @app.route(
'/<database_name>/sale_don_confiao/search_products/<product_name>', "/<database_name>/sale_don_confiao/search_products/<product_name>", methods=["GET"]
methods=['GET']) )
@allow_null_origin @allow_null_origin
@with_pool @with_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):
Product = pool.get('product.product') Product = pool.get("product.product")
with Transaction().set_context( with Transaction().set_context({"company": 1, "locations": [3]}):
{'company': 1, 'locations': [3]}): products = Product.search_read(
products = Product.search_read([ [("name", "ilike", f"%{product_name}%")],
('name', 'ilike', f'%{product_name}%') order=[("id", "ASC")],
], order=[ fields_names=[
('id', 'ASC') "id",
], fields_names=[ "name",
'id', "template.list_price",
'name', "default_uom.name",
'template.list_price', "description",
'default_uom.name', "quantity",
'description', ],
'quantity', )
])
return products return products
@app.route( @app.route("/<database_name>/sale_don_confiao/sale/<sale_id>", methods=["GET"])
'/<database_name>/sale_don_confiao/sale/<sale_id>',
methods=['GET'])
@allow_null_origin @allow_null_origin
@with_pool @with_pool
@with_transaction() @with_transaction()
@don_confiao_application @don_confiao_application
def sale(request, pool, sale_id: int): def sale(request, pool, sale_id: int):
Sale = pool.get('sale.sale') Sale = pool.get("sale.sale")
if request.method == 'GET': if request.method == "GET":
sales = Sale.search_read([ sales = Sale.search_read(
('id', '=', sale_id) [("id", "=", sale_id)],
], order=[ order=[("id", "ASC")],
('id', 'ASC') fields_names=[
], fields_names=[ "id",
'id', "party.name",
'party.name', "sale_date",
'sale_date', "shipment_address.street",
'shipment_address.street', "untaxed_amount_cache",
'untaxed_amount_cache', "tax_amount_cache",
'tax_amount_cache', "total_amount_cache",
'total_amount_cache', ],
]) )
return sales return sales
@app.route( @app.route("/<database_name>/sale_don_confiao/post_sale", methods=["POST"])
'/<database_name>/sale_don_confiao/post_sale',
methods=['POST'])
@allow_null_origin @allow_null_origin
@with_pool @with_pool
@with_transaction() @with_transaction()
@don_confiao_application @don_confiao_application
def post_sale(request, pool): def post_sale(request, pool):
Sale = pool.get('sale.sale') Sale = pool.get("sale.sale")
data = json.loads( data = json.loads(request.get_data().decode())
request.get_data().decode()
)
sales = Sale.create([dict(data)]) sales = Sale.create([dict(data)])
@ -168,54 +166,43 @@ def post_sale(request, pool):
return sales[0].id return sales[0].id
@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
@with_transaction() @with_transaction()
@don_confiao_application @don_confiao_application
def sales(request, pool): def sales(request, pool):
Sale = pool.get('sale.sale') Sale = pool.get("sale.sale")
sales = Sale.search_read([ sales = Sale.search_read(
], order=[ [],
('id', 'ASC') order=[("id", "ASC")],
], fields_names=[ fields_names=[
'id', "id",
'party.name', "party.name",
'sale_date', "sale_date",
'shipment_address.street', "shipment_address.street",
'untaxed_amount_cache', "untaxed_amount_cache",
'tax_amount_cache', "tax_amount_cache",
'total_amount_cache', "total_amount_cache",
]) ],
)
return sales return sales
@app.route('/<database_name>/sale_don_confiao/payment_methods', methods=[ @app.route("/<database_name>/sale_don_confiao/payment_methods", methods=["GET"])
'GET'])
@allow_null_origin @allow_null_origin
@with_pool @with_pool
@with_transaction() @with_transaction()
@don_confiao_application @don_confiao_application
def payment_methods(request, pool): def payment_methods(request, pool):
if request.method == 'GET': if request.method == "GET":
payment_methods = [ payment_methods = [
{ {"text": "Efectivo", "value": "CASH"},
"text": "Efectivo", {"text": "Confiar", "value": "CONFIAR"},
"value": "CASH" {"text": "Bancolombia", "value": "BANCOLOMBIA"},
},
{
"text": "Confiar",
"value": "CONFIAR"
},
{
"text": "Bancolombia",
"value": "BANCOLOMBIA"
}
] ]
response_data = { response_data = {"payment_methods": payment_methods}
"payment_methods": payment_methods
}
return response_data, 200 return response_data, 200