1、优化中控接口14-16

This commit is contained in:
yuxianghui
2024-02-23 17:29:04 +08:00
parent 475b45b293
commit db48ef396e
8 changed files with 98 additions and 96 deletions

View File

@@ -692,6 +692,15 @@ class CAMWorkOrderProgramKnifePlan(models.Model):
names = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)
return categories.browse(names)
@api.onchange('plan_execute_status')
def _onchange_plan_execute_status(self):
for record in self:
if record.plan_execute_status == '已完成':
self.env['sf.cnc.processing'].register_cnc_processing(record)
def knife_plan_cnc_processing(self):
self.env['sf.cnc.processing'].register_cnc_processing(self)
def apply_for_tooling(self):
"""
申请装刀
@@ -757,13 +766,12 @@ class CAMWorkOrderProgramKnifePlan(models.Model):
if functional_tools:
for functional_tool in functional_tools:
if functional_tool.on_tool_stock_num == 0:
# self.env['sf.cnc.processing'].register_cnc_processing(cnc_processing)
if functional_tool.tool_stock_num == 0 and functional_tool.side_shelf_num == 0:
status = True
else:
status = True
if status:
self.env['sf.cam.work.order.program.knife.plan'].sudo().create({
knife_plan = self.env['sf.cam.work.order.program.knife.plan'].sudo().create({
'name': cnc_processing.workorder_id.production_id.name,
'cam_procedure_code': cnc_processing.program_name,
'filename': cnc_processing.cnc_id.name,
@@ -778,6 +786,8 @@ class CAMWorkOrderProgramKnifePlan(models.Model):
'shank_model': cnc_processing.cutting_tool_handle_type,
'estimated_processing_time': cnc_processing.estimated_processing_time,
})
# 创建装刀请求
knife_plan.apply_for_tooling()
class FunctionalToolAssembly(models.Model):

View File

@@ -1,5 +1,6 @@
import json
import requests
import logging
from odoo import models, api, fields
from odoo.exceptions import ValidationError
from odoo.addons.sf_base.commons.common import Common
@@ -21,6 +22,10 @@ class SfMaintenanceEquipmentTool(models.Model):
used_value = fields.Integer('已使用值(min)', related='functional_tool_name_id.used_value')
tool_install_time = fields.Datetime('机内装刀时间')
# def write_tool(self, datas):
# if datas:
# print(datas)
@api.model_create_multi
def create(self, vals_list):
tools = super().create(vals_list)
@@ -38,23 +43,52 @@ class SfMaintenanceEquipment(models.Model):
# ==========机床当前刀库实时信息接口==========
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)
# 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)
headers = {'Authorization': 'Ba F2CF5DCC-1A00-4234-9E95-65603F70CC8A'}
crea_url = "https://x24467i973.zicp.fun/AutoDeviceApi/GetToolInfos"
params = {"DeviceId": self.name}
r = requests.get(crea_url, params=params, headers=headers)
ret = r.json()
print(ret)
if r == 200:
logging.info('register_equipment_tool:%s' % ret)
datas = ret['Datas']
self.write_maintenance_equipment_tool(datas)
if ret['Succeed']:
return "机床当前刀库实时信息指令发送成功"
else:
raise ValidationError("机床当前刀库实时信息指令发送失败")
def write_maintenance_equipment_tool(self, datas):
if datas:
for data in datas:
maintenance_equipment_id = self.search([('name', '=', data['DeviceId'])])
if maintenance_equipment_id:
equipment_tool_id = self.env['maintenance.equipment.tool'].sudo().search(
[('equipment_id', '=', maintenance_equipment_id.id), ('code', '=', data['ToolId'])])
functional_tool_id = self.env['sf.functional.cutting.tool.entity'].sudo().search(
[('rfid', '=', data['RfidCode'])])
time = None
if data['AddDatetime']:
datatime = str(data['AddDatetime'])
time = fields.Datetime.from_string(datatime[0:10] + ' ' + datatime[11:19])
if equipment_tool_id and functional_tool_id:
tool_install_time = {'Nomal': '正常', 'Warning': '报警'}
equipment_tool_id.write({
'functional_tool_name_id': functional_tool_id.id,
'tool_install_time': time
})
functional_tool_id.write({
'max_lifetime_value': data['MaxLife'],
'used_value': data['UseLife'],
'functional_tool_status': tool_install_time.get(data['State'])
})
else:
raise ValidationError('获取的【%s】设备不存在!!!' % data['DeviceId'])
else:
raise ValidationError('没有获取到刀具库信息!!!')
class StockLot(models.Model):
_inherit = 'stock.lot'

View File

@@ -1,5 +1,6 @@
import json
import requests
import logging
from odoo import fields, models, api
from odoo.exceptions import ValidationError
from odoo.addons.sf_base.commons.common import Common
@@ -10,21 +11,22 @@ class CNCprocessing(models.Model):
_description = 'CNC加工用刀检测'
# ==========MES装刀指令接口==========
def register_cnc_processing(self, cnc_processing):
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)
def register_cnc_processing(self, knife_plan):
# 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)
headers = {'Authorization': 'Ba F2CF5DCC-1A00-4234-9E95-65603F70CC8A'}
strurl = "https://x24467i973.zicp.fun/AutoDeviceApi/ToolLoadInstruct"
val = {
'DeviceId': cnc_processing.workorder_id.machine_tool_name,
'RfidCode': None,
'ToolId': cnc_processing.cutting_tool_no
'DeviceId': knife_plan.machine_table_name,
'RfidCode': knife_plan.sf_functional_tool_assembly_id.rfid,
'ToolId': int(knife_plan.cutter_spacing_code_id.code[1:])
}
kw = json.dumps(val, ensure_ascii=False)
r = requests.post(strurl, json={}, data={'kw': kw, 'token': token}, headers=headers)
r = requests.post(strurl, json=val, headers=headers)
ret = r.json()
if r == 200:
logging.info('register_cnc_processing:%s' % ret)
if ret['Succeed']:
return "MES装刀指令发送成功"
else:
raise ValidationError("MES装刀指令发送失败")