70 lines
2.6 KiB
Python
70 lines
2.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
import logging
|
|
import json
|
|
import base64
|
|
from odoo import http
|
|
from odoo.http import request
|
|
|
|
|
|
class Manufacturing_Connect(http.Controller):
|
|
|
|
@http.route('/AutoDeviceApi/ToolInventory', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
|
|
cors="*")
|
|
def get_functional_tool_inventory_Info(self, **kw):
|
|
"""
|
|
功能刀具清单接口
|
|
:param kw:
|
|
:return:
|
|
"""
|
|
logging.info('get_functional_tool_inventory_Info:%s' % kw)
|
|
try:
|
|
datas = request.httprequest.data
|
|
ret = json.loads(datas)
|
|
# ret = json.loads(ret['result'])
|
|
logging.info('DeviceId:%s' % ret)
|
|
tool_inventory = request.env['sf.tool.inventory'].sudo().search([])
|
|
|
|
res = {'Succeed': True, 'Datas': []}
|
|
if tool_inventory:
|
|
for item in tool_inventory:
|
|
res['Datas'].append({
|
|
'ToolName': item.name,
|
|
'GroupName': item.tool_groups_id.name,
|
|
'Lifetime': item.life_span
|
|
})
|
|
except Exception as e:
|
|
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
|
logging.info('get_functional_tool_inventory_Info error:%s' % e)
|
|
return json.JSONEncoder().encode(res)
|
|
|
|
@http.route('/AutoDeviceApi/ToolEntity', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
|
|
cors="*")
|
|
def get_functional_tool_entity_Info(self, **kw):
|
|
"""
|
|
功能刀具列表接口
|
|
:param kw:
|
|
:return:
|
|
"""
|
|
logging.info('get_functional_tool_entity_Info:%s' % kw)
|
|
try:
|
|
datas = request.httprequest.data
|
|
ret = json.loads(datas)
|
|
# ret = json.loads(ret['result'])
|
|
logging.info('DeviceId:%s' % ret)
|
|
functional_tools = request.env['sf.functional.cutting.tool.entity'].sudo().search([])
|
|
|
|
res = {'Succeed': True, 'Datas': []}
|
|
if functional_tools:
|
|
for item in functional_tools:
|
|
res['Datas'].append({
|
|
'Rfid': item.rfid,
|
|
'ToolName': item.tool_name_id.name,
|
|
'GroupName': item.tool_groups_id.name,
|
|
'MaxLifetime': item.max_lifetime_value,
|
|
'KnifeHandle': item.cutting_tool_cutterhandle_model_id.name
|
|
})
|
|
except Exception as e:
|
|
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
|
logging.info('get_functional_tool_entity_Info error:%s' % e)
|
|
return json.JSONEncoder().encode(res)
|