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()
|
||||
)
|
||||
|
||||
party = Party()
|
||||
party.name = data['name']
|
||||
party.save()
|
||||
Party.create([dict(data)])
|
||||
|
||||
|
||||
@app.route(
|
||||
@ -113,27 +111,46 @@ def search_products(request, pool, product_name: str):
|
||||
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
|
||||
@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
|
||||
if request.method == 'GET':
|
||||
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/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'])
|
||||
@ -155,4 +172,5 @@ def sales(request, pool):
|
||||
'tax_amount_cache',
|
||||
'total_amount_cache',
|
||||
])
|
||||
|
||||
return sales
|
||||
|
@ -202,3 +202,37 @@ class DonConfiaoApiRouteTestCase(
|
||||
}))
|
||||
|
||||
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