Feat: Endpoint Sale POST
This commit is contained in:
parent
d745ee12e3
commit
6afd7795a7
@ -30,9 +30,7 @@ def parties(request, pool):
|
|||||||
request.get_data().decode()
|
request.get_data().decode()
|
||||||
)
|
)
|
||||||
|
|
||||||
party = Party()
|
Party.create([dict(data)])
|
||||||
party.name = data['name']
|
|
||||||
party.save()
|
|
||||||
|
|
||||||
|
|
||||||
@app.route(
|
@app.route(
|
||||||
@ -113,27 +111,46 @@ def search_products(request, pool, product_name: str):
|
|||||||
return products
|
return products
|
||||||
|
|
||||||
|
|
||||||
@app.route('/<database_name>/sale_don_confiao/sale/<sale_id>', methods=['GET'])
|
@app.route(
|
||||||
|
'/<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')
|
||||||
sales = Sale.search_read([
|
if request.method == 'GET':
|
||||||
('id', '=', sale_id)
|
sales = Sale.search_read([
|
||||||
], order=[
|
('id', '=', sale_id)
|
||||||
('id', 'ASC')
|
], order=[
|
||||||
], fields_names=[
|
('id', 'ASC')
|
||||||
'id',
|
], fields_names=[
|
||||||
'party.name',
|
'id',
|
||||||
'sale_date',
|
'party.name',
|
||||||
'shipment_address.street',
|
'sale_date',
|
||||||
'untaxed_amount_cache',
|
'shipment_address.street',
|
||||||
'tax_amount_cache',
|
'untaxed_amount_cache',
|
||||||
'total_amount_cache',
|
'tax_amount_cache',
|
||||||
])
|
'total_amount_cache',
|
||||||
return sales
|
])
|
||||||
|
return sales
|
||||||
|
|
||||||
|
|
||||||
|
@app.route(
|
||||||
|
'/<database_name>/sale_don_confiao/post_sale',
|
||||||
|
methods=['POST'])
|
||||||
|
@allow_null_origin
|
||||||
|
@with_pool
|
||||||
|
@with_transaction()
|
||||||
|
@don_confiao_application
|
||||||
|
def post_sale(request, pool):
|
||||||
|
Sale = pool.get('sale.sale')
|
||||||
|
data = json.loads(
|
||||||
|
request.get_data().decode()
|
||||||
|
)
|
||||||
|
|
||||||
|
Sale.create([dict(data)])
|
||||||
|
|
||||||
|
|
||||||
@app.route('/<database_name>/sale_don_confiao/sales', methods=['GET'])
|
@app.route('/<database_name>/sale_don_confiao/sales', methods=['GET'])
|
||||||
@ -155,4 +172,5 @@ def sales(request, pool):
|
|||||||
'tax_amount_cache',
|
'tax_amount_cache',
|
||||||
'total_amount_cache',
|
'total_amount_cache',
|
||||||
])
|
])
|
||||||
|
|
||||||
return sales
|
return sales
|
||||||
|
@ -202,3 +202,37 @@ class DonConfiaoApiRouteTestCase(
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||||
|
|
||||||
|
# def test_post_sale(self):
|
||||||
|
# pool = Pool(DB_NAME)
|
||||||
|
# transaction = Transaction().start(DB_NAME, user=0)
|
||||||
|
# with transaction:
|
||||||
|
# party = pool.get('party.party').search([])[0]
|
||||||
|
# company, = pool.get('company.company').search([])
|
||||||
|
# currency, = pool.get('currency.currency').search([])
|
||||||
|
# product = pool.get('product.product').search([
|
||||||
|
# ('salable', '=', True)])[0]
|
||||||
|
# uom = pool.get('product.uom').search([])[0]
|
||||||
|
|
||||||
|
# client = self.client()
|
||||||
|
# response = client.post(
|
||||||
|
# f'/{self.db_name}/sale_don_confiao/post_sale',
|
||||||
|
# headers={
|
||||||
|
# 'Authorization': f'bearer {self.key}',
|
||||||
|
# }, data=json.dumps({
|
||||||
|
# "party": party.id,
|
||||||
|
# "company": company.id,
|
||||||
|
# # "currency": currency.id,
|
||||||
|
# # "invoice_method": "order",
|
||||||
|
# # "shipment_method": "order",
|
||||||
|
# # "lines": [["create", [{
|
||||||
|
# # "type": "line",
|
||||||
|
# # "product": product.id,
|
||||||
|
# # "quantity": "1",
|
||||||
|
# # "unit_price": "10",
|
||||||
|
# # "unit": uom.id
|
||||||
|
# # }]]],
|
||||||
|
# # "state": "draft"
|
||||||
|
# }))
|
||||||
|
|
||||||
|
# self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||||
|
Loading…
Reference in New Issue
Block a user