Fix: Tests SaleApiOrder
This commit is contained in:
parent
d7f746db0a
commit
13618e7dda
@ -1,7 +1,8 @@
|
|||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
from . import sale_order, user
|
from . import sale_order, user, routes
|
||||||
|
|
||||||
__all__ = ['register']
|
__all__ = [
|
||||||
|
'register', 'routes']
|
||||||
|
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
|
22
routes.py
22
routes.py
@ -1,4 +1,5 @@
|
|||||||
from trytond.wsgi import app
|
from trytond.wsgi import app
|
||||||
|
from trytond.transaction import Transaction
|
||||||
from trytond.protocols.wrappers import (
|
from trytond.protocols.wrappers import (
|
||||||
with_pool,
|
with_pool,
|
||||||
with_transaction,
|
with_transaction,
|
||||||
@ -6,20 +7,21 @@ from trytond.protocols.wrappers import (
|
|||||||
allow_null_origin)
|
allow_null_origin)
|
||||||
import json
|
import json
|
||||||
|
|
||||||
sale_order = user_application('sale_order')
|
sale_order_application = user_application('sale_order')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/<database_name>/sale_order/order', methods=['POST'])
|
@app.route(
|
||||||
|
'/<database_name>/sale_order/order', methods=['POST'])
|
||||||
@allow_null_origin
|
@allow_null_origin
|
||||||
@with_pool
|
@with_pool
|
||||||
@with_transaction()
|
@with_transaction()
|
||||||
@sale_order
|
@sale_order_application
|
||||||
def order(request, pool):
|
def order(request, pool):
|
||||||
raise Exception(request)
|
|
||||||
Order = pool.get('sale.order')
|
Order = pool.get('sale.order')
|
||||||
if request.method == 'POST':
|
with Transaction().set_context(
|
||||||
data = json.loads(
|
{'company': 1, 'locations': [3]}):
|
||||||
request.get_data().decode()
|
if request.method == 'POST':
|
||||||
)
|
data = json.loads(
|
||||||
|
request.get_data().decode()
|
||||||
Order.create([dict(data)])
|
)
|
||||||
|
Order.create([dict(data)])
|
||||||
|
@ -33,12 +33,15 @@ class SaleOrder (Workflow, ModelView, ModelSQL):
|
|||||||
party = fields.Many2One(
|
party = fields.Many2One(
|
||||||
'party.party', "Party", required=True, states=_states)
|
'party.party', "Party", required=True, states=_states)
|
||||||
order_address = fields.Many2One(
|
order_address = fields.Many2One(
|
||||||
'party.address', 'Address', required=True, states=_states)
|
'party.address', 'Address', states=_states)
|
||||||
pickup_location = fields.Selection([
|
pickup_location = fields.Selection([
|
||||||
("on_site", "On Site"),
|
("on_site", "On Site"),
|
||||||
("at_home", "At Home")], 'Pickup Location', states=_states)
|
("at_home", "At Home")], 'Pickup Location', states=_states)
|
||||||
order_mobile = fields.Char('Mobile', states=_states)
|
order_mobile = fields.Char('Mobile', states=_states)
|
||||||
date = fields.Date("Date", required=True, states=_states)
|
date = fields.Date("Date", required=True, states={
|
||||||
|
'readonly': Eval('state').in_(['confirmed', 'done']),
|
||||||
|
'required': Eval('pickup_location') == 'at_home'
|
||||||
|
})
|
||||||
lines = fields.One2Many(
|
lines = fields.One2Many(
|
||||||
'order.line', 'order', 'Lines', states=_states)
|
'order.line', 'order', 'Lines', states=_states)
|
||||||
total_order = fields.Function(
|
total_order = fields.Function(
|
||||||
|
23
tests/SaleOrderApiTest.py
Normal file
23
tests/SaleOrderApiTest.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import pudb
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
url = 'http://localhost:18030'
|
||||||
|
key = 'f46f14d77db646b0ac0802e7bdab9cbb' + (
|
||||||
|
'1d53ad96387242e1918c45854dce5238707fed31daa64cab88569d119512153') + (
|
||||||
|
'64db6ced393b44f198ab9a3967b6f4ddf')
|
||||||
|
db = 'tryton'
|
||||||
|
application_name = 'sale_order'
|
||||||
|
base_url = '{}/{}/{}'.format(url, db, application_name)
|
||||||
|
|
||||||
|
post_sale_order = requests.post(
|
||||||
|
base_url + '/order',
|
||||||
|
headers={
|
||||||
|
'Authorization': f'bearer {key}',
|
||||||
|
}, data=json.dumps({
|
||||||
|
"party": 2573,
|
||||||
|
"pickup_location": 'on_site'
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
pudb.set_trace()
|
@ -13,6 +13,7 @@ class SaleOrderApiRouteTestCase(RouteTestCase):
|
|||||||
"""Sale Order API Routes"""
|
"""Sale Order API Routes"""
|
||||||
|
|
||||||
module = 'sale_order'
|
module = 'sale_order'
|
||||||
|
|
||||||
key = uuid.uuid4().hex
|
key = uuid.uuid4().hex
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -28,6 +29,13 @@ class SaleOrderApiRouteTestCase(RouteTestCase):
|
|||||||
ProductTemplate = pool.get('product.template')
|
ProductTemplate = pool.get('product.template')
|
||||||
Product = pool.get('product.product')
|
Product = pool.get('product.product')
|
||||||
Uom = pool.get('product.uom')
|
Uom = pool.get('product.uom')
|
||||||
|
Application = pool.get('res.user.application')
|
||||||
|
Application(
|
||||||
|
key=self.key,
|
||||||
|
user=1,
|
||||||
|
application='sale_order',
|
||||||
|
state='validated').save()
|
||||||
|
|
||||||
self.productTemplate, = ProductTemplate.create([{
|
self.productTemplate, = ProductTemplate.create([{
|
||||||
'name': 'Product',
|
'name': 'Product',
|
||||||
'default_uom': Uom.search([('name', '=', 'Unit')])[0].id,
|
'default_uom': Uom.search([('name', '=', 'Unit')])[0].id,
|
||||||
@ -48,6 +56,7 @@ class SaleOrderApiRouteTestCase(RouteTestCase):
|
|||||||
'Authorization': f'bearer {self.key}',
|
'Authorization': f'bearer {self.key}',
|
||||||
}, data=json.dumps({
|
}, data=json.dumps({
|
||||||
"party": self.party.id,
|
"party": self.party.id,
|
||||||
|
"pickup_location": 'on_site'
|
||||||
}))
|
}))
|
||||||
|
|
||||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||||
|
Loading…
Reference in New Issue
Block a user