feat: Implemented get associate party to contact_mechanism
This commit is contained in:
parent
becf5f929a
commit
09cabd6798
31
routes.py
31
routes.py
@ -10,6 +10,37 @@ import json
|
|||||||
sale_order_application = user_application('sale_order')
|
sale_order_application = user_application('sale_order')
|
||||||
|
|
||||||
|
|
||||||
|
@app.route(
|
||||||
|
'/<database_name>/sale_order/associate_party/<contact_method>', methods=[
|
||||||
|
"GET"])
|
||||||
|
@allow_null_origin
|
||||||
|
@with_pool
|
||||||
|
@with_transaction()
|
||||||
|
@sale_order_application
|
||||||
|
def get_associate_party(request, pool, contact_method: str):
|
||||||
|
ContactMechanism = pool.get('party.contact_mechanism')
|
||||||
|
associate_contact_method = ContactMechanism.search(
|
||||||
|
[('value', 'ilike', contact_method)])
|
||||||
|
if associate_contact_method:
|
||||||
|
response_data = {
|
||||||
|
'id': associate_contact_method[0].id,
|
||||||
|
'associate_party': associate_contact_method[0].party.id,
|
||||||
|
'status': 'success',
|
||||||
|
'type': associate_contact_method[0].type,
|
||||||
|
'message': 'Associate Party found',
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.dumps(response_data), 200
|
||||||
|
response_data = {
|
||||||
|
'id': None,
|
||||||
|
'associate_party': None,
|
||||||
|
'status': 'success',
|
||||||
|
'type': None,
|
||||||
|
'message': 'Associate Party not found',
|
||||||
|
}
|
||||||
|
return json.dumps(response_data), 404
|
||||||
|
|
||||||
|
|
||||||
@app.route(
|
@app.route(
|
||||||
'/<database_name>/sale_order/order/<order>', methods=['GET'])
|
'/<database_name>/sale_order/order/<order>', methods=['GET'])
|
||||||
@allow_null_origin
|
@allow_null_origin
|
||||||
|
@ -2,7 +2,8 @@ import pudb
|
|||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
|
||||||
url = 'http://localhost:18030'
|
|
||||||
|
url = 'http://localhost:8000'
|
||||||
key = 'f46f14d77db646b0ac0802e7bdab9cbb' + (
|
key = 'f46f14d77db646b0ac0802e7bdab9cbb' + (
|
||||||
'1d53ad96387242e1918c45854dce5238707fed31daa64cab88569d119512153') + (
|
'1d53ad96387242e1918c45854dce5238707fed31daa64cab88569d119512153') + (
|
||||||
'64db6ced393b44f198ab9a3967b6f4ddf')
|
'64db6ced393b44f198ab9a3967b6f4ddf')
|
||||||
@ -10,6 +11,13 @@ db = 'tryton'
|
|||||||
application_name = 'sale_order'
|
application_name = 'sale_order'
|
||||||
base_url = '{}/{}/{}'.format(url, db, application_name)
|
base_url = '{}/{}/{}'.format(url, db, application_name)
|
||||||
|
|
||||||
|
|
||||||
|
get_associate_party = requests.get(
|
||||||
|
base_url + '/associate_party/alejandro.ayala@gmail.com',
|
||||||
|
headers={
|
||||||
|
'Authorization': f'bearer {key}',
|
||||||
|
})
|
||||||
|
|
||||||
post_sale_order = requests.post(
|
post_sale_order = requests.post(
|
||||||
base_url + '/order',
|
base_url + '/order',
|
||||||
headers={
|
headers={
|
||||||
|
@ -12,63 +12,79 @@ from trytond.tests.tools import activate_modules
|
|||||||
class SaleOrderApiRouteTestCase(RouteTestCase):
|
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
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
activate_modules('sale_order', create_company)
|
activate_modules("sale_order", create_company)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pool = Pool(DB_NAME)
|
pool = Pool(DB_NAME)
|
||||||
transaction = Transaction().start(DB_NAME, 0, _lock_tables=[
|
transaction = Transaction().start(
|
||||||
'product_product'])
|
DB_NAME, 0, _lock_tables=["product_product"])
|
||||||
with transaction:
|
with transaction:
|
||||||
Party = pool.get('party.party')
|
Party = pool.get("party.party")
|
||||||
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 = pool.get("res.user.application")
|
||||||
|
|
||||||
Application(
|
Application(
|
||||||
key=self.key,
|
key=self.key,
|
||||||
user=1,
|
user=1,
|
||||||
application='sale_order',
|
application="sale_order",
|
||||||
state='validated'
|
state="validated"
|
||||||
).save()
|
).save()
|
||||||
|
|
||||||
self.unit = Uom.search([('name', '=', 'Unit')])[0].id
|
self.unit = Uom.search([("name", "=", "Unit")])[0].id
|
||||||
self.productTemplate, = ProductTemplate.create([{
|
(self.productTemplate,) = ProductTemplate.create(
|
||||||
'name': 'Product',
|
[
|
||||||
'default_uom': self.unit,
|
{
|
||||||
}])
|
"name": "Product",
|
||||||
|
"default_uom": self.unit,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
self.product, = Product.create([
|
self.product, = Product.create([
|
||||||
{'template': self.productTemplate.id}
|
{"template": self.productTemplate.id}])
|
||||||
])
|
|
||||||
|
|
||||||
self.party, = Party.create([{
|
self.party, = Party.create([{
|
||||||
'name': "Dunkan"
|
"name": "Dunkan",
|
||||||
|
"contact_mechanisms": [['create', [{
|
||||||
|
'type': 'mobile',
|
||||||
|
'value': '3102223334'
|
||||||
|
}]]]
|
||||||
}])
|
}])
|
||||||
|
|
||||||
def test_post_sale_order(self):
|
def test_post_sale_order(self):
|
||||||
client = self.client()
|
client = self.client()
|
||||||
response = client.post(
|
response = client.post(
|
||||||
f'/{self.db_name}/sale_order/order',
|
f"/{self.db_name}/sale_order/order",
|
||||||
headers={
|
headers={
|
||||||
'Authorization': f'bearer {self.key}',
|
"Authorization": f"bearer {self.key}",
|
||||||
}, data=json.dumps({
|
},
|
||||||
"party": self.party.id,
|
data=json.dumps(
|
||||||
"pickup_location": 'on_site',
|
{
|
||||||
"lines": [[
|
"party": self.party.id,
|
||||||
"create", [{
|
"pickup_location": "on_site",
|
||||||
"product": self.product.id,
|
"lines": [
|
||||||
"unit": self.unit,
|
[
|
||||||
"quantity": "5",
|
"create",
|
||||||
"unitprice": "10"
|
[
|
||||||
}]
|
{
|
||||||
]]
|
"product": self.product.id,
|
||||||
}))
|
"unit": self.unit,
|
||||||
|
"quantity": "5",
|
||||||
|
"unitprice": "10",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||||
|
|
||||||
@ -77,92 +93,150 @@ class SaleOrderApiRouteTestCase(RouteTestCase):
|
|||||||
|
|
||||||
order = json.loads(
|
order = json.loads(
|
||||||
client.post(
|
client.post(
|
||||||
f'/{self.db_name}/sale_order/order',
|
f"/{self.db_name}/sale_order/order",
|
||||||
headers={
|
headers={
|
||||||
'Authorization': f'bearer {self.key}',
|
"Authorization": f"bearer {self.key}",
|
||||||
}, data=json.dumps({
|
},
|
||||||
"party": self.party.id,
|
data=json.dumps(
|
||||||
"pickup_location": 'on_site',
|
{
|
||||||
"lines": [[
|
"party": self.party.id,
|
||||||
"create", [{
|
"pickup_location": "on_site",
|
||||||
"product": self.product.id,
|
"lines": [
|
||||||
"unit": self.unit,
|
[
|
||||||
"quantity": "5",
|
"create",
|
||||||
"unitprice": "10"
|
[
|
||||||
}]
|
{
|
||||||
]]
|
"product": self.product.id,
|
||||||
})).get_data().decode())
|
"unit": self.unit,
|
||||||
|
"quantity": "5",
|
||||||
|
"unitprice": "10",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.get_data()
|
||||||
|
.decode()
|
||||||
|
)
|
||||||
|
|
||||||
response = client.get(
|
response = client.get(
|
||||||
f"/{self.db_name}/sale_order/order/{json.loads(order[0])['id']}",
|
f"/{self.db_name}/sale_order/order/{json.loads(order[0])['id']}",
|
||||||
headers={
|
headers={
|
||||||
'Authorization': f'bearer {self.key}',
|
"Authorization": f"bearer {self.key}",
|
||||||
})
|
},
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||||
self.assertEqual(len(
|
self.assertEqual(len(json.loads(response.text)), 1)
|
||||||
json.loads(response.text)
|
|
||||||
), 1)
|
|
||||||
|
|
||||||
def test_confirm_sale_order(self):
|
def test_confirm_sale_order(self):
|
||||||
client = self.client()
|
client = self.client()
|
||||||
|
|
||||||
order = json.loads(
|
order = json.loads(
|
||||||
client.post(
|
client.post(
|
||||||
f'/{self.db_name}/sale_order/order',
|
f"/{self.db_name}/sale_order/order",
|
||||||
headers={
|
headers={
|
||||||
'Authorization': f'bearer {self.key}',
|
"Authorization": f"bearer {self.key}",
|
||||||
}, data=json.dumps({
|
},
|
||||||
"party": self.party.id,
|
data=json.dumps(
|
||||||
"pickup_location": 'on_site',
|
{
|
||||||
"lines": [[
|
"party": self.party.id,
|
||||||
"create", [{
|
"pickup_location": "on_site",
|
||||||
"product": self.product.id,
|
"lines": [
|
||||||
"unit": self.unit,
|
[
|
||||||
"quantity": "5",
|
"create",
|
||||||
"unitprice": "10"
|
[
|
||||||
}]
|
{
|
||||||
]]
|
"product": self.product.id,
|
||||||
})).get_data().decode())
|
"unit": self.unit,
|
||||||
|
"quantity": "5",
|
||||||
|
"unitprice": "10",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.get_data()
|
||||||
|
.decode()
|
||||||
|
)
|
||||||
|
|
||||||
confirm_url = f"/{self.db_name}/sale_order/confirm_order/"
|
confirm_url = f"/{self.db_name}/sale_order/confirm_order/"
|
||||||
order_id = json.loads(order[0])['id']
|
order_id = json.loads(order[0])["id"]
|
||||||
response = client.post(
|
response = client.post(
|
||||||
f"{confirm_url}{order_id}",
|
f"{confirm_url}{order_id}",
|
||||||
headers={
|
headers={
|
||||||
'Authorization': f'bearer {self.key}',
|
"Authorization": f"bearer {self.key}",
|
||||||
})
|
},
|
||||||
|
)
|
||||||
|
|
||||||
response_data = json.loads(
|
response_data = json.loads(json.loads(response.text)[0])
|
||||||
json.loads(response.text)[0])
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||||
self.assertEqual(response_data['state'], 'confirmed')
|
self.assertEqual(response_data["state"], "confirmed")
|
||||||
|
|
||||||
def test_post_line_order(self):
|
def test_post_line_order(self):
|
||||||
client = self.client()
|
client = self.client()
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
f'/{self.db_name}/sale_order/order',
|
f"/{self.db_name}/sale_order/order",
|
||||||
headers={
|
headers={"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'})
|
"pickup_location": "on_site"}),
|
||||||
)
|
)
|
||||||
|
|
||||||
order = json.loads(json.loads(response.text)[0]).get("id")
|
order = json.loads(json.loads(response.text)[0]).get("id")
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
f'/{self.db_name}/sale_order/{order}/order_line',
|
f"/{self.db_name}/sale_order/{order}/order_line",
|
||||||
headers={
|
headers={
|
||||||
'Authorization': f'bearer {self.key}',
|
"Authorization": f"bearer {self.key}",
|
||||||
}, data=json.dumps({
|
},
|
||||||
"order": order,
|
data=json.dumps(
|
||||||
"product": self.product.id,
|
{
|
||||||
"unit": self.unit,
|
"order": order,
|
||||||
"quantity": "5",
|
"product": self.product.id,
|
||||||
"unitprice": "10"
|
"unit": self.unit,
|
||||||
}))
|
"quantity": "5",
|
||||||
|
"unitprice": "10",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||||
|
|
||||||
|
def test_get_party_asociate_contact_method(self):
|
||||||
|
"""
|
||||||
|
Recibe un numbero de telofono y retorna el tercero asociado
|
||||||
|
a este numero de telofono.
|
||||||
|
Args:
|
||||||
|
phone: string
|
||||||
|
Return:
|
||||||
|
party: int
|
||||||
|
"""
|
||||||
|
client = self.client()
|
||||||
|
response = client.get(
|
||||||
|
f"/{self.db_name}/sale_order/associate_party/3102223334",
|
||||||
|
headers={
|
||||||
|
"Authorization": f"bearer {self.key}",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||||
|
self.assertEqual(json.loads(response.text)[1], 200)
|
||||||
|
self.assertEqual(json.loads(json.loads(response.text)[0])[
|
||||||
|
'associate_party'], 2)
|
||||||
|
|
||||||
|
def test_create_contact_method(self):
|
||||||
|
"""
|
||||||
|
Crea un tercero asociandolo a un metodo de contacto
|
||||||
|
|
||||||
|
Args:
|
||||||
|
email, phone : string
|
||||||
|
Return:
|
||||||
|
party: int
|
||||||
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user