Feat(WIP): Sale Order API
This commit is contained in:
parent
674f6c9f7b
commit
d7f746db0a
@ -1,11 +1,12 @@
|
||||
from trytond.pool import Pool
|
||||
from . import sale_order
|
||||
from . import sale_order, user
|
||||
|
||||
__all__ = ['register']
|
||||
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
user.UserApplication,
|
||||
sale_order.SaleOrder,
|
||||
sale_order.OrderLine,
|
||||
module='sale_order', type_='model')
|
||||
|
25
routes.py
Normal file
25
routes.py
Normal file
@ -0,0 +1,25 @@
|
||||
from trytond.wsgi import app
|
||||
from trytond.protocols.wrappers import (
|
||||
with_pool,
|
||||
with_transaction,
|
||||
user_application,
|
||||
allow_null_origin)
|
||||
import json
|
||||
|
||||
sale_order = user_application('sale_order')
|
||||
|
||||
|
||||
@app.route('/<database_name>/sale_order/order', methods=['POST'])
|
||||
@allow_null_origin
|
||||
@with_pool
|
||||
@with_transaction()
|
||||
@sale_order
|
||||
def order(request, pool):
|
||||
raise Exception(request)
|
||||
Order = pool.get('sale.order')
|
||||
if request.method == 'POST':
|
||||
data = json.loads(
|
||||
request.get_data().decode()
|
||||
)
|
||||
|
||||
Order.create([dict(data)])
|
53
tests/test_api_sale_order.py
Normal file
53
tests/test_api_sale_order.py
Normal file
@ -0,0 +1,53 @@
|
||||
from trytond.tests.test_tryton import RouteTestCase
|
||||
from trytond.pool import Pool
|
||||
from http import HTTPStatus
|
||||
import uuid
|
||||
import json
|
||||
from trytond.tests.test_tryton import DB_NAME
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.modules.company.tests.tools import create_company
|
||||
from trytond.tests.tools import activate_modules
|
||||
|
||||
|
||||
class SaleOrderApiRouteTestCase(RouteTestCase):
|
||||
"""Sale Order API Routes"""
|
||||
|
||||
module = 'sale_order'
|
||||
key = uuid.uuid4().hex
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
activate_modules('sale_order', create_company)
|
||||
|
||||
def setUp(self):
|
||||
pool = Pool(DB_NAME)
|
||||
transaction = Transaction().start(DB_NAME, 0, _lock_tables=[
|
||||
'product_product'])
|
||||
with transaction:
|
||||
Party = pool.get('party.party')
|
||||
ProductTemplate = pool.get('product.template')
|
||||
Product = pool.get('product.product')
|
||||
Uom = pool.get('product.uom')
|
||||
self.productTemplate, = ProductTemplate.create([{
|
||||
'name': 'Product',
|
||||
'default_uom': Uom.search([('name', '=', 'Unit')])[0].id,
|
||||
}])
|
||||
self.product, = Product.create([
|
||||
{'template': self.productTemplate.id}
|
||||
])
|
||||
|
||||
self.party, = Party.create([{
|
||||
'name': "Dunkan"
|
||||
}])
|
||||
|
||||
def test_post_sale_order(self):
|
||||
client = self.client()
|
||||
response = client.post(
|
||||
f'/{self.db_name}/sale_order/order',
|
||||
headers={
|
||||
'Authorization': f'bearer {self.key}',
|
||||
}, data=json.dumps({
|
||||
"party": self.party.id,
|
||||
}))
|
||||
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
14
user.py
Normal file
14
user.py
Normal file
@ -0,0 +1,14 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.pool import PoolMeta
|
||||
|
||||
|
||||
class UserApplication(metaclass=PoolMeta):
|
||||
__name__ = 'res.user.application'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(UserApplication, cls).__setup__()
|
||||
cls.application.selection.append(
|
||||
('sale_order', 'SaleOrder')
|
||||
)
|
Loading…
Reference in New Issue
Block a user