112 lines
4.5 KiB
Python
112 lines
4.5 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/GetWoInfo', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False,
|
|
cors="*")
|
|
def get_Work_Info(self, **kw):
|
|
"""
|
|
自动化传递工单号获取工单信息
|
|
:param kw:
|
|
:return:
|
|
"""
|
|
logging.info('get_Work_Info:%s' % kw)
|
|
try:
|
|
res = {'Succeed': True, 'Datas': []}
|
|
datas = request.httprequest.data
|
|
ret = json.loads(datas)
|
|
ret = json.loads(ret['result'])
|
|
logging.info('RfidCode:%s' % ret)
|
|
workorder = request.env['mrp.workorder'].sudo().search([('name', '=', ret['RfidCode'])])
|
|
if workorder:
|
|
for item in workorder:
|
|
res['Datas'].append({
|
|
'BillId': item.production_id.name,
|
|
'ProductionLine': item.production_line,
|
|
'CraftName': item.name,
|
|
'Quantity': 1,
|
|
'MaterialId': item.product_id.default_code,
|
|
'MaterialName': item.product_id.name,
|
|
# 'Spec':item.mat,
|
|
'Material': item.materials_type_id.name
|
|
})
|
|
except Exception as e:
|
|
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
|
logging.info('get_Work_Info error:%s' % e)
|
|
return json.JSONEncoder().encode(res)
|
|
|
|
|
|
@http.route('/AutoDeviceApi/FeedBackStart', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
|
|
cors="*")
|
|
def button_Work_START(self, **kw):
|
|
"""
|
|
工单任务开始
|
|
:param kw:
|
|
:return:
|
|
"""
|
|
logging.info('get_Work_Info:%s' % kw)
|
|
try:
|
|
res = {'Succeed': True, 'Datas': []}
|
|
datas = request.httprequest.data
|
|
ret = json.loads(datas)
|
|
if not ret['BillId']:
|
|
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '未传制造订单号'}
|
|
return json.JSONEncoder().encode(res)
|
|
if not ret['CraftId']:
|
|
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '未传工序名称'}
|
|
return json.JSONEncoder().encode(res)
|
|
if not ret['DeviceId']:
|
|
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '未传设备号'}
|
|
return json.JSONEncoder().encode(res)
|
|
production_id = ret['BillId']
|
|
routing_type = ret['CraftId']
|
|
workorder = request.env['mrp.workorder'].sudo().search(
|
|
[('production_id', '=', production_id), ('routing_type', '=', routing_type)], limit=1)
|
|
workorder.button_start()
|
|
|
|
|
|
except Exception as e:
|
|
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
|
logging.info('get_Work_Info error:%s' % e)
|
|
return json.JSONEncoder().encode(res)
|
|
|
|
@http.route('/AutoDeviceApi/FeedBackEnd', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
|
|
cors="*")
|
|
def button_Work_End(self, **kw):
|
|
"""
|
|
工单任务结束
|
|
:param kw:
|
|
:return:
|
|
"""
|
|
logging.info('get_Work_Info:%s' % kw)
|
|
try:
|
|
res = {'Succeed': True, 'Datas': []}
|
|
datas = request.httprequest.data
|
|
ret = json.loads(datas)
|
|
if not ret['BillId']:
|
|
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '未传制造订单号'}
|
|
return json.JSONEncoder().encode(res)
|
|
if not ret['CraftId']:
|
|
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '未传工序名称'}
|
|
return json.JSONEncoder().encode(res)
|
|
if not ret['DeviceId']:
|
|
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '未传设备号'}
|
|
return json.JSONEncoder().encode(res)
|
|
production_id = ret['BillId']
|
|
routing_type = ret['CraftId']
|
|
workorder = request.env['mrp.workorder'].sudo().search(
|
|
[('production_id', '=', production_id), ('routing_type', '=', routing_type)], limit=1)
|
|
workorder.button_finish()
|
|
|
|
|
|
except Exception as e:
|
|
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
|
logging.info('get_Work_Info error:%s' % e)
|
|
return json.JSONEncoder().encode(res)
|