Feat: GET sales
This commit is contained in:
parent
a1b947f852
commit
cd1450e11b
@ -1,3 +1,4 @@
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.wsgi import app
|
||||
from trytond.protocols.wrappers import (
|
||||
with_pool,
|
||||
@ -11,9 +12,7 @@ don_confiao_application = user_application(
|
||||
|
||||
|
||||
@app.route('/<database_name>/sale_don_confiao/parties', methods=[
|
||||
'GET'])
|
||||
@app.route('/<database_name>/sale_don_confiao/parties', methods=[
|
||||
'POST'])
|
||||
'GET', 'POST'])
|
||||
@allow_null_origin
|
||||
@with_pool
|
||||
@with_transaction()
|
||||
@ -42,10 +41,32 @@ def parties(request, pool):
|
||||
@with_pool
|
||||
@with_transaction()
|
||||
@don_confiao_application
|
||||
def get_products(request, pool):
|
||||
def products(request, pool):
|
||||
Product = pool.get('product.product')
|
||||
products = Product.search_read(
|
||||
[],
|
||||
order=[('id', 'ASC')],
|
||||
fields_names=['id', 'name'])
|
||||
return products
|
||||
|
||||
|
||||
@app.route('/<database_name>/sale_don_confiao/sales', methods=['GET'])
|
||||
@allow_null_origin
|
||||
@with_pool
|
||||
@with_transaction()
|
||||
@don_confiao_application
|
||||
def sales(request, pool):
|
||||
data = json.loads(
|
||||
request.get_data().decode()
|
||||
)
|
||||
with Transaction().set_context(
|
||||
{'company': data['company']}):
|
||||
Sale = pool.get('sale.sale')
|
||||
sales = Sale.search_read([
|
||||
# ('company', '=', data['company']),
|
||||
# ('state', '=', 'draft')
|
||||
], order=[
|
||||
('id', 'ASC')
|
||||
], fields_names=['id', 'party.name'])
|
||||
|
||||
return sales
|
||||
|
@ -5,6 +5,7 @@ import uuid
|
||||
import json
|
||||
from trytond.tests.test_tryton import DB_NAME
|
||||
from trytond.transaction import Transaction
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
class DonConfiaoApiRouteTestCase(
|
||||
@ -19,11 +20,8 @@ class DonConfiaoApiRouteTestCase(
|
||||
def setUpDatabase(cls):
|
||||
pool = Pool()
|
||||
Application = pool.get('res.user.application')
|
||||
Company = pool.get('company.company')
|
||||
Party = pool.get('party.party')
|
||||
|
||||
# Product = pool.get('product.product')
|
||||
|
||||
Application(
|
||||
key=cls.key,
|
||||
user=1,
|
||||
@ -34,12 +32,6 @@ class DonConfiaoApiRouteTestCase(
|
||||
customer.name = 'Dunkan'
|
||||
customer.save()
|
||||
|
||||
company = Company(
|
||||
party=1,
|
||||
currency=1
|
||||
)
|
||||
company.save()
|
||||
|
||||
def test_get_parties(self):
|
||||
client = self.client()
|
||||
response = client.get(
|
||||
@ -111,3 +103,63 @@ class DonConfiaoApiRouteTestCase(
|
||||
response.get_data().decode())
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
self.assertEqual(len(products), 1)
|
||||
|
||||
def test_get_sales(self):
|
||||
pool = Pool(DB_NAME)
|
||||
transaction = Transaction().start(DB_NAME, user=0, _lock_tables=[
|
||||
'product_product'])
|
||||
with transaction:
|
||||
Company = pool.get(
|
||||
'company.company')
|
||||
Currency = pool.get('currency.currency')
|
||||
Sale = pool.get('sale.sale')
|
||||
currency, = Currency.create([{
|
||||
'name': 'COP',
|
||||
'code': 'COP'
|
||||
}])
|
||||
company, = Company.create([{
|
||||
'party': 1,
|
||||
'currency': currency.id
|
||||
}])
|
||||
|
||||
ProductTemplate = pool.get('product.template')
|
||||
Product = pool.get('product.product')
|
||||
Uom = pool.get('product.uom')
|
||||
template, = ProductTemplate.create([
|
||||
{'name': 'Product',
|
||||
'salable': True,
|
||||
'default_uom': Uom.search([('name', '=', 'Unit')])[0].id,
|
||||
'sale_uom': Uom.search([('name', '=', 'Unit')])[0].id
|
||||
}
|
||||
])
|
||||
|
||||
product, = Product.create([
|
||||
{'template': template.id}])
|
||||
|
||||
sale, = Sale.create([{
|
||||
'party': 1,
|
||||
'company': 1,
|
||||
'currency': 1,
|
||||
'lines': [['create', [{
|
||||
'type': 'line',
|
||||
'product': product.id,
|
||||
'quantity': 1,
|
||||
'unit_price': Decimal(10),
|
||||
'unit': Uom.search([('name', '=', 'Unit')])[0].id
|
||||
}]]],
|
||||
'state': 'draft'
|
||||
}])
|
||||
|
||||
self.assertIsInstance(sale, Sale)
|
||||
self.assertEqual(sale.state, 'draft')
|
||||
|
||||
client = self.client()
|
||||
response = client.get(
|
||||
f'/{self.db_name}/sale_don_confiao/sales',
|
||||
headers={
|
||||
'Authorization': f'bearer {self.key}',
|
||||
}, data=json.dumps({
|
||||
'company': company.id
|
||||
}))
|
||||
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
|
@ -4,4 +4,5 @@ depends:
|
||||
ir
|
||||
party
|
||||
product
|
||||
sale
|
||||
xml:
|
||||
|
Loading…
Reference in New Issue
Block a user