add endpoint product

This commit is contained in:
wilson gomez 2022-02-09 16:02:09 -05:00
parent f08cb36694
commit 11305adcf7
1 changed files with 32 additions and 0 deletions

View File

@ -741,4 +741,36 @@ def create_app(dbname):
return send(exec_(_method))
@app.route("/product/", methods=['POST'])
@require_appkey
def get_product():
data = json.loads(request.data.decode("utf-8"))
id_product = None
if data.get('id'):
id_product = data['id']
@tryton.transaction()
def _method():
Product = _pool.get('product.product')
fields_names = [
'id', 'code', 'name', 'template.categories',
'template.sale_price_w_tax', 'template.name']
products = Product.search_read(
['id', '=', id_product],
fields_names=fields_names
)
if products:
product = products[0]
value = {
'id': product['id'],
'name': product['template.']['name'],
'code': product['code'],
'sale_price': float(product['template.']['sale_price_w_tax']),
'categories': product['template.']['categories.'],
'images': ''
}
return value
return send(exec_(_method))
return app