Feat: Add enpoints SaleOrder
This commit is contained in:
parent
13618e7dda
commit
b78ec4549b
31
routes.py
31
routes.py
@ -16,7 +16,7 @@ sale_order_application = user_application('sale_order')
|
||||
@with_pool
|
||||
@with_transaction()
|
||||
@sale_order_application
|
||||
def order(request, pool):
|
||||
def post_order(request, pool):
|
||||
Order = pool.get('sale.order')
|
||||
with Transaction().set_context(
|
||||
{'company': 1, 'locations': [3]}):
|
||||
@ -24,4 +24,31 @@ def order(request, pool):
|
||||
data = json.loads(
|
||||
request.get_data().decode()
|
||||
)
|
||||
Order.create([dict(data)])
|
||||
order, = Order.create([dict(data)])
|
||||
|
||||
return order.id
|
||||
|
||||
|
||||
@app.route(
|
||||
'/<database_name>/sale_order/order/<order>', methods=['GET'])
|
||||
@allow_null_origin
|
||||
@with_pool
|
||||
@with_transaction()
|
||||
@sale_order_application
|
||||
def get_order(request, pool, order: int):
|
||||
Order = pool.get('sale.order')
|
||||
with Transaction().set_context({
|
||||
'company': 1,
|
||||
'locations': [3]}):
|
||||
if request.method == 'GET':
|
||||
orders = Order.search_read([
|
||||
('id', '=', order)
|
||||
], order=[
|
||||
('id', 'ASC')
|
||||
], fields_names=[
|
||||
'id',
|
||||
'party',
|
||||
'lines'
|
||||
])
|
||||
|
||||
return orders
|
||||
|
@ -16,8 +16,19 @@ post_sale_order = requests.post(
|
||||
'Authorization': f'bearer {key}',
|
||||
}, data=json.dumps({
|
||||
"party": 2573,
|
||||
"pickup_location": 'on_site'
|
||||
"pickup_location": 'on_site',
|
||||
"lines": [[
|
||||
"create", [{
|
||||
"quantity": "5",
|
||||
"unitprice": "10"
|
||||
}]]]
|
||||
})
|
||||
)
|
||||
|
||||
get_sale_order = requests.get(
|
||||
base_url + '/order/1',
|
||||
headers={
|
||||
'Authorization': f'bearer {key}',
|
||||
})
|
||||
|
||||
pudb.set_trace()
|
||||
|
@ -30,15 +30,18 @@ class SaleOrderApiRouteTestCase(RouteTestCase):
|
||||
Product = pool.get('product.product')
|
||||
Uom = pool.get('product.uom')
|
||||
Application = pool.get('res.user.application')
|
||||
|
||||
Application(
|
||||
key=self.key,
|
||||
user=1,
|
||||
application='sale_order',
|
||||
state='validated').save()
|
||||
state='validated'
|
||||
).save()
|
||||
|
||||
self.unit = Uom.search([('name', '=', 'Unit')])[0].id
|
||||
self.productTemplate, = ProductTemplate.create([{
|
||||
'name': 'Product',
|
||||
'default_uom': Uom.search([('name', '=', 'Unit')])[0].id,
|
||||
'default_uom': self.unit,
|
||||
}])
|
||||
self.product, = Product.create([
|
||||
{'template': self.productTemplate.id}
|
||||
@ -56,7 +59,47 @@ class SaleOrderApiRouteTestCase(RouteTestCase):
|
||||
'Authorization': f'bearer {self.key}',
|
||||
}, data=json.dumps({
|
||||
"party": self.party.id,
|
||||
"pickup_location": 'on_site'
|
||||
"pickup_location": 'on_site',
|
||||
"lines": [[
|
||||
"create", [{
|
||||
"product": self.product.id,
|
||||
"unit": self.unit,
|
||||
"quantity": "5",
|
||||
"unitprice": "10"
|
||||
}]
|
||||
]]
|
||||
}))
|
||||
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
|
||||
def test_get_sale_orders(self):
|
||||
client = self.client()
|
||||
|
||||
order = client.post(
|
||||
f'/{self.db_name}/sale_order/order',
|
||||
headers={
|
||||
'Authorization': f'bearer {self.key}',
|
||||
}, data=json.dumps({
|
||||
"party": self.party.id,
|
||||
"pickup_location": 'on_site',
|
||||
"lines": [[
|
||||
"create", [{
|
||||
"product": self.product.id,
|
||||
"unit": self.unit,
|
||||
"quantity": "5",
|
||||
"unitprice": "10"
|
||||
}]
|
||||
]]
|
||||
}))
|
||||
|
||||
response = client.get(
|
||||
f'/{self.db_name}/sale_order/order/{order.text}',
|
||||
headers={
|
||||
'Authorization': f'bearer {self.key}',
|
||||
})
|
||||
|
||||
orders = json.loads(
|
||||
response.get_data().decode())
|
||||
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
self.assertEqual(len(orders), 1)
|
||||
|
Loading…
Reference in New Issue
Block a user