Merge branch 'develop' of https://e.coding.net/jikimo-hn/jikimo_sfs/jikimo_sf into feature/修改机床参数bug
This commit is contained in:
@@ -22,7 +22,7 @@ class Manufacturing_Connect(http.Controller):
|
||||
ret = json.loads(datas)
|
||||
# ret = json.loads(ret['result'])
|
||||
logging.info('DeviceId:%s' % ret)
|
||||
tool_groups = request.env['sf.tool.groups'].sudo().search([('active', '=', True)])
|
||||
tool_groups = request.env['sf.tool.groups'].sudo().search([])
|
||||
|
||||
res = {'Succeed': True, 'Datas': []}
|
||||
if tool_groups:
|
||||
|
||||
@@ -21,7 +21,6 @@ class Http(models.AbstractModel):
|
||||
def _auth_method_sf_token(cls):
|
||||
# 从headers.environ中获取对方传过来的token,timestamp,加密的校验字符串
|
||||
datas = request.httprequest.headers.environ
|
||||
logging.info(datas)
|
||||
if 'HTTP_TOKEN' in datas:
|
||||
_logger.info('token:%s' % datas['HTTP_TOKEN'])
|
||||
# 查询密钥
|
||||
@@ -34,8 +33,6 @@ class Http(models.AbstractModel):
|
||||
# if abs(int(datas['HTTP_TIMESTAMP']) - timestamp_str) > deltime.seconds:
|
||||
# raise AuthenticationError('请求已过期')
|
||||
post_time = int(datas['HTTP_TIMESTAMP'])
|
||||
_logger.info('HTTP_TIMESTAMP:%s' % post_time)
|
||||
_logger.info('HTTP_CHECKSTR:%s' % datas['HTTP_CHECKSTR'])
|
||||
datetime_post = datetime.fromtimestamp(post_time)
|
||||
datetime_now = datetime.now().replace(microsecond=0)
|
||||
datetime_del = datetime_now + timedelta(seconds=5)
|
||||
@@ -43,9 +40,12 @@ class Http(models.AbstractModel):
|
||||
raise AuthenticationError('请求已过期')
|
||||
check_str = '%s%s%s' % (datas['HTTP_TOKEN'], post_time, factory_secret.sf_secret_key)
|
||||
check_sf_str = hashlib.sha1(check_str.encode('utf-8')).hexdigest()
|
||||
_logger.info('check_str:%s' % check_sf_str)
|
||||
_logger.info('HTTP_TIMESTAMP:%s' % post_time)
|
||||
_logger.info('HTTP_CHECKSTR:%s' % datas['HTTP_CHECKSTR'])
|
||||
_logger.info('check_sf_str:%s' % check_sf_str)
|
||||
# if check_sf_str != datas['HTTP_CHECKSTR']:
|
||||
# raise AuthenticationError('数据校验不通过')
|
||||
_logger.info('check_str:%s' % check_str)
|
||||
_logger.info('sf_secret_key:%s' % factory_secret.sf_secret_key)
|
||||
if check_sf_str != datas['HTTP_CHECKSTR']:
|
||||
raise AuthenticationError('数据校验不通过')
|
||||
else:
|
||||
raise AuthenticationError('请求参数中无token')
|
||||
|
||||
@@ -22,13 +22,13 @@ class Manufacturing_Connect(http.Controller):
|
||||
ret = json.loads(datas)
|
||||
logging.info('RfidCode:%s' % ret['RfidCode'])
|
||||
if 'RfidCode' in ret:
|
||||
workorder = request.env['mrp.workorder'].sudo().search(
|
||||
[('rfid_code', '=', ret['RfidCode']), ('routing_type', '=', '装夹预调')])
|
||||
workorder = request.env['mrp.workorder'].sudo().search([('rfid_code', '=', ret['RfidCode'])])
|
||||
if workorder:
|
||||
for item in workorder:
|
||||
res['Datas'].append({
|
||||
'BillId': item.production_id.name,
|
||||
'ProductionLine': item.production_id.production_line_id.id,
|
||||
'SortId': item.sequence,
|
||||
'CraftName': item.name,
|
||||
'Quantity': 1,
|
||||
'MaterialId': item.product_id.default_code,
|
||||
@@ -60,11 +60,13 @@ class Manufacturing_Connect(http.Controller):
|
||||
datas = request.httprequest.data
|
||||
ret = json.loads(datas)
|
||||
if 'ProductionLine' in ret:
|
||||
workorder = request.env['mrp.workorder'].sudo().get_plan_workorder(ret['ProductionLine'])
|
||||
workorder_ids = request.env['mrp.workorder'].sudo().get_plan_workorder(ret['ProductionLine'])
|
||||
else:
|
||||
ProductionLine = False
|
||||
workorder = request.env['mrp.workorder'].sudo().get_plan_workorder(ProductionLine)
|
||||
workorder_ids = request.env['mrp.workorder'].sudo().get_plan_workorder(ProductionLine)
|
||||
logging.info('RfidCode:%s' % ret)
|
||||
logging.info('workorder_ids:%s' % workorder_ids)
|
||||
workorder = request.env['mrp.workorder'].sudo().search(workorder_ids)
|
||||
if workorder:
|
||||
for item in workorder:
|
||||
date_planned_start = ''
|
||||
@@ -119,7 +121,8 @@ class Manufacturing_Connect(http.Controller):
|
||||
'XOffset': 0 if not item.material_center_point else offset[0],
|
||||
'YOffset': 0 if not item.material_center_point else offset[1],
|
||||
'ZOffet': 0 if not item.material_center_point else offset[2],
|
||||
'COffset': 'G54' if not item.X_deviation_angle else item.X_deviation_angle
|
||||
'COffset': 0 if not item.X_deviation_angle else item.X_deviation_angle,
|
||||
'Coordinate': 'G54'
|
||||
})
|
||||
else:
|
||||
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '该rfid暂未有对应的工件预调(前置三元检测)工单'}
|
||||
@@ -293,17 +296,15 @@ class Manufacturing_Connect(http.Controller):
|
||||
logging.info('NCProgDolod error:%s' % e)
|
||||
return json.JSONEncoder().encode(res)
|
||||
|
||||
|
||||
@http.route('/AutoDeviceApi/LocationChange', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False,
|
||||
cors="*")
|
||||
def NCProgDolod(self, **kw):
|
||||
|
||||
def LocationChange(self, **kw):
|
||||
"""
|
||||
库位变更
|
||||
:param kw:
|
||||
:return:
|
||||
"""
|
||||
logging.info('NCProgDolod:%s' % kw)
|
||||
logging.info('LocationChange:%s' % kw)
|
||||
try:
|
||||
res = {'Succeed': True, 'Datas': []}
|
||||
datas = request.httprequest.data
|
||||
@@ -315,6 +316,62 @@ class Manufacturing_Connect(http.Controller):
|
||||
res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传RfidCode字段'}
|
||||
except Exception as e:
|
||||
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
||||
logging.info('NCProgDolod error:%s' % e)
|
||||
logging.info('LocationChange error:%s' % e)
|
||||
return json.JSONEncoder().encode(res)
|
||||
|
||||
@http.route('/AutoDeviceApi/AGVToProduct', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
|
||||
cors="*")
|
||||
def AGVToProduct(self, **kw):
|
||||
"""
|
||||
AGV运送上产线(完成)
|
||||
:param kw:
|
||||
:return:
|
||||
"""
|
||||
logging.info('AGVToProduct:%s' % kw)
|
||||
try:
|
||||
res = {'Succeed': True}
|
||||
datas = request.httprequest.data
|
||||
ret = json.loads(datas)
|
||||
if 'DeviceId' in ret:
|
||||
logging.info('DeviceId:%s' % ret['DeviceId'])
|
||||
workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search(
|
||||
[('feeder_station_destination', '=', ret['DeviceId'])])
|
||||
if workpiece_delivery:
|
||||
workpiece_delivery.production_id.write({'production_line_state': '已上产线'})
|
||||
else:
|
||||
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '该DeviceId没有对应的工件配送数据'}
|
||||
else:
|
||||
res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传DeviceId字段'}
|
||||
except Exception as e:
|
||||
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
||||
logging.info('AGVToProduct error:%s' % e)
|
||||
return json.JSONEncoder().encode(res)
|
||||
|
||||
@http.route('/AutoDeviceApi/AGVDownProduct', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
|
||||
cors="*")
|
||||
def AGVDownProduct(self, **kw):
|
||||
"""
|
||||
MES调度AGV,搬运零件AGV托盘到产线接驳站。
|
||||
生产线接受到零件AGV托盘到位信号后,把生产合格或特采的零件,机器人搬运零件到AGV接驳站中,触发AGV运送下产线接口。
|
||||
:param kw:
|
||||
:return:
|
||||
"""
|
||||
logging.info('AGVDownProduct:%s' % kw)
|
||||
try:
|
||||
res = {'Succeed': True}
|
||||
datas = request.httprequest.data
|
||||
ret = json.loads(datas)
|
||||
if 'DeviceId' in ret:
|
||||
logging.info('DeviceId:%s' % ret['DeviceId'])
|
||||
workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search(
|
||||
[('feeder_station_destination', '=', ret['DeviceId'])])
|
||||
if workpiece_delivery:
|
||||
workpiece_delivery.production_id.write({'production_line_state': '已下产线'})
|
||||
else:
|
||||
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '该DeviceId没有对应的工件配送数据'}
|
||||
else:
|
||||
res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传DeviceId字段'}
|
||||
except Exception as e:
|
||||
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
||||
logging.info('AGVDownProduct error:%s' % e)
|
||||
return json.JSONEncoder().encode(res)
|
||||
|
||||
@@ -52,6 +52,8 @@ class MrpProduction(models.Model):
|
||||
glb_file = fields.Binary("glb模型文件")
|
||||
production_line_id = fields.Many2one('sf.production.line', string='生产线')
|
||||
plan_start_processing_time = fields.Datetime('计划开始加工时间')
|
||||
production_line_state = fields.Selection([('待上产线', '待上产线'), ('已上产线', '已上产线'), ('已下产线', '已下产线')],
|
||||
string='上/下产线', default='待上产线')
|
||||
|
||||
|
||||
@api.depends(
|
||||
|
||||
@@ -135,6 +135,17 @@ class ResMrpWorkOrder(models.Model):
|
||||
workpiece_delivery_ids = fields.One2many('sf.workpiece.delivery', 'workorder_id', '工件配送')
|
||||
is_delivery = fields.Boolean('是否配送完成', default=False)
|
||||
rfid_code = fields.Char('RFID')
|
||||
production_line_id = fields.Many2one('sf.production.line', related='production_id.production_line_id',
|
||||
string='生产线', store=True)
|
||||
production_line_state = fields.Selection(related='production_id.production_line_state',
|
||||
string='上/下产线', store=True)
|
||||
|
||||
@api.onchange('rfid_code')
|
||||
def compute_rfid(self):
|
||||
workorder = self.env['mrp.workorder'].search([('production_id', '=', self.production_id)])
|
||||
if workorder:
|
||||
for item in workorder:
|
||||
item.rfid_code = self.rfid_code
|
||||
|
||||
def get_plan_workorder(self, production_line):
|
||||
tomorrow = (date.today() + timedelta(days=+1)).strftime("%Y-%m-%d")
|
||||
@@ -875,5 +886,3 @@ class CMMprogram(models.Model):
|
||||
post_processing_name = fields.Char('后处理名称')
|
||||
program_date = fields.Datetime('程序日期')
|
||||
workorder_id = fields.Many2one('mrp.workorder', string="工单")
|
||||
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@
|
||||
<field name="programming_state" readonly="1"/>
|
||||
<field name="production_line_id" readonly="1"/>
|
||||
<field name="plan_start_processing_time" readonly="1"/>
|
||||
<field name="production_line_state" readonly="1"/>
|
||||
</xpath>
|
||||
<xpath expr="//header//button[@name='action_cancel']" position="replace">
|
||||
<button name="action_cancel" type="object" string="取消" data-hotkey="z"
|
||||
|
||||
@@ -170,14 +170,15 @@
|
||||
attrs='{"invisible": [("routing_type","in",("获取CNC加工程序","切割"))]}'/>
|
||||
<field name="equipment_id"
|
||||
attrs='{"invisible": [("routing_type","in",("获取CNC加工程序","切割"))]}'/>
|
||||
<field name="production_line_state"
|
||||
attrs='{"invisible": [("routing_type","in",("获取CNC加工程序","切割"))]}'/>
|
||||
<field name="functional_fixture_id"
|
||||
attrs='{"invisible": [("routing_type","!=","装夹预调")]}'/>
|
||||
<field name="functional_fixture_code" force_save="1"
|
||||
attrs='{"invisible": [("routing_type","!=","装夹预调")]}'/>
|
||||
<field name="functional_fixture_type_id" force_save="1"
|
||||
attrs='{"invisible": [("routing_type","!=","装夹预调")]}'/>
|
||||
<field name="rfid_code"
|
||||
attrs='{"invisible": [("routing_type","!=","装夹预调")]}'/>
|
||||
<field name="rfid_code" force_save="1"/>
|
||||
</group>
|
||||
<group attrs='{"invisible": [("routing_type","=","获取CNC加工程序")]}'>
|
||||
<div>
|
||||
|
||||
@@ -8,53 +8,53 @@ from odoo.http import request
|
||||
|
||||
class Manufacturing_Connect(http.Controller):
|
||||
|
||||
@http.route('/AutoDeviceApi/GetToolInfo', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
|
||||
cors="*")
|
||||
def get_equipment_tool_Info(self, **kw):
|
||||
"""
|
||||
机床刀库实时信息
|
||||
:param kw:
|
||||
:return:
|
||||
"""
|
||||
logging.info('get_equipment_tool_Info:%s' % kw)
|
||||
try:
|
||||
datas = request.httprequest.data
|
||||
ret = json.loads(datas)
|
||||
ret = json.loads(ret.get('result'))
|
||||
logging.info('DeviceId:%s' % ret)
|
||||
equipment = request.env['maintenance.equipment'].sudo().search([('name', '=', ret['DeviceId'])])
|
||||
|
||||
res = {'Succeed': True, 'Datas': []}
|
||||
if equipment:
|
||||
for item in equipment:
|
||||
data = []
|
||||
for equipment_tool_id in item.product_template_ids:
|
||||
functional_tool_id = self.env['sf.functional.cutting.tool.entity'].sudo().search(
|
||||
[('code', '=', equipment_tool_id.tool_code)])
|
||||
|
||||
alarm_time = None
|
||||
if functional_tool_id.functional_tool_status == '报警':
|
||||
alarm_time = self.env['sf.functional.tool.warning'].sudo().search(
|
||||
[('code', '=', equipment_tool_id.tool_code)]).alarm_time
|
||||
equipment_tool = {
|
||||
'RfidCode': None,
|
||||
'ToolId': equipment_tool_id.code,
|
||||
'ToolName': equipment_tool_id.functional_tool_name_id.name,
|
||||
'MaxLife': equipment_tool_id.life_value_max,
|
||||
'UseLife': equipment_tool_id.used_value,
|
||||
'AddDatetime': equipment_tool_id.tool_install_time,
|
||||
'State': functional_tool_id.functional_tool_status,
|
||||
'WarnDate': alarm_time if alarm_time else False
|
||||
}
|
||||
data.append(equipment_tool)
|
||||
res['Datas'].append({
|
||||
'DeviceId': item.name,
|
||||
'Data': data
|
||||
})
|
||||
except Exception as e:
|
||||
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
||||
logging.info('get_equipment_tool_Info error:%s' % e)
|
||||
return json.JSONEncoder().encode(res)
|
||||
# @http.route('/AutoDeviceApi/GetToolInfo', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
|
||||
# cors="*")
|
||||
# def get_equipment_tool_Info(self, **kw):
|
||||
# """
|
||||
# 机床刀库实时信息
|
||||
# :param kw:
|
||||
# :return:
|
||||
# """
|
||||
# logging.info('get_equipment_tool_Info:%s' % kw)
|
||||
# try:
|
||||
# datas = request.httprequest.data
|
||||
# ret = json.loads(datas)
|
||||
# ret = json.loads(ret.get('result'))
|
||||
# logging.info('DeviceId:%s' % ret)
|
||||
# equipment = request.env['maintenance.equipment'].sudo().search([('name', '=', ret['DeviceId'])])
|
||||
#
|
||||
# res = {'Succeed': True, 'Datas': []}
|
||||
# if equipment:
|
||||
# for item in equipment:
|
||||
# data = []
|
||||
# for equipment_tool_id in item.product_template_ids:
|
||||
# functional_tool_id = self.env['sf.functional.cutting.tool.entity'].sudo().search(
|
||||
# [('code', '=', equipment_tool_id.tool_code)])
|
||||
#
|
||||
# alarm_time = None
|
||||
# if functional_tool_id.functional_tool_status == '报警':
|
||||
# alarm_time = self.env['sf.functional.tool.warning'].sudo().search(
|
||||
# [('code', '=', equipment_tool_id.tool_code)]).alarm_time
|
||||
# equipment_tool = {
|
||||
# 'RfidCode': None,
|
||||
# 'ToolId': equipment_tool_id.code,
|
||||
# 'ToolName': equipment_tool_id.functional_tool_name_id.name,
|
||||
# 'MaxLife': equipment_tool_id.life_value_max,
|
||||
# 'UseLife': equipment_tool_id.used_value,
|
||||
# 'AddDatetime': equipment_tool_id.tool_install_time,
|
||||
# 'State': functional_tool_id.functional_tool_status,
|
||||
# 'WarnDate': alarm_time if alarm_time else False
|
||||
# }
|
||||
# data.append(equipment_tool)
|
||||
# res['Datas'].append({
|
||||
# 'DeviceId': item.name,
|
||||
# 'Data': data
|
||||
# })
|
||||
# except Exception as e:
|
||||
# res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
||||
# logging.info('get_equipment_tool_Info error:%s' % e)
|
||||
# return json.JSONEncoder().encode(res)
|
||||
|
||||
@http.route('/AutoDeviceApi/ToolGroup', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
|
||||
cors="*")
|
||||
@@ -70,7 +70,7 @@ class Manufacturing_Connect(http.Controller):
|
||||
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([('active', '=', True)])
|
||||
functional_tools = request.env['sf.functional.cutting.tool.entity'].sudo().search([])
|
||||
|
||||
res = {'Succeed': True, 'Datas': []}
|
||||
if functional_tools:
|
||||
|
||||
@@ -734,7 +734,7 @@ class CAMWorkOrderProgramKnifePlan(models.Model):
|
||||
撤回装刀申请
|
||||
:return:
|
||||
"""
|
||||
self.env['sf.functional.tool.assembly'].search(
|
||||
self.env['sf.functional.tool.assembly'].sudo().search(
|
||||
[('assembly_order_code', '=', self.sf_functional_tool_assembly_id.assembly_order_code),
|
||||
('loading_task_source', '=', '0')]).unlink()
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import json
|
||||
import requests
|
||||
from odoo import models, api, fields
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.addons.sf_base.commons.common import Common
|
||||
|
||||
|
||||
class SfMaintenanceEquipmentTool(models.Model):
|
||||
@@ -29,6 +32,30 @@ class SfMaintenanceEquipmentTool(models.Model):
|
||||
return tools
|
||||
|
||||
|
||||
class SfMaintenanceEquipment(models.Model):
|
||||
_inherit = 'maintenance.equipment'
|
||||
_description = '设备机床刀库'
|
||||
|
||||
# ==========机床当前刀库实时信息接口==========
|
||||
def register_equipment_tool(self):
|
||||
sf_sync_config = self.env['res.config.settings'].get_values()
|
||||
token = sf_sync_config['token']
|
||||
sf_secret_key = sf_sync_config['sf_secret_key']
|
||||
headers = Common.get_headers(self, token, sf_secret_key)
|
||||
strurl = "https://x24467i973.zicp.fun/AutoDeviceApi/GetToolInfos"
|
||||
val = {
|
||||
"DeviceId": self.name
|
||||
}
|
||||
kw = json.dumps(val, ensure_ascii=False)
|
||||
r = requests.get(strurl, json={}, data={'kw': kw, 'token': token}, headers=headers)
|
||||
ret = r.json()
|
||||
print(ret)
|
||||
if r == 200:
|
||||
return "机床当前刀库实时信息指令发送成功"
|
||||
else:
|
||||
raise ValidationError("机床当前刀库实时信息指令发送失败")
|
||||
|
||||
|
||||
class StockLot(models.Model):
|
||||
_inherit = 'stock.lot'
|
||||
|
||||
|
||||
@@ -11,12 +11,11 @@ class CNCprocessing(models.Model):
|
||||
|
||||
# ==========MES装刀指令接口==========
|
||||
def register_cnc_processing(self, cnc_processing):
|
||||
create_url = '/AutoDeviceApi/ToolLoadInstruct'
|
||||
sf_sync_config = self.env['res.config.settings'].get_values()
|
||||
token = sf_sync_config['token']
|
||||
sf_secret_key = sf_sync_config['sf_secret_key']
|
||||
headers = Common.get_headers(self, token, sf_secret_key)
|
||||
strurl = sf_sync_config['sf_url'] + create_url
|
||||
strurl = "https://x24467i973.zicp.fun/AutoDeviceApi/ToolLoadInstruct"
|
||||
val = {
|
||||
'DeviceId': cnc_processing.workorder_id.machine_tool_name,
|
||||
'RfidCode': None,
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<xpath expr="//page[@name='sf_equipment_product_template']" position="replace">
|
||||
<page string="标准刀库" name="sf_equipment_product_template"
|
||||
attrs="{'invisible': [('equipment_type', '!=', '机床')]}">
|
||||
<button string="获取机床刀库信息" name="register_equipment_tool" type="object" class="btn-primary"/>
|
||||
<field name='product_template_ids'>
|
||||
<tree editable='bottom'>
|
||||
<field name="code"/>
|
||||
|
||||
Reference in New Issue
Block a user