48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
import json
|
|
import requests
|
|
from odoo import fields, models, api
|
|
from odoo.exceptions import ValidationError
|
|
from odoo.addons.sf_base.commons.common import Common
|
|
|
|
|
|
class CNCprocessing(models.Model):
|
|
_inherit = 'sf.cnc.processing'
|
|
_description = 'CNC加工用刀检测'
|
|
|
|
# ==========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
|
|
val = {
|
|
'DeviceId': cnc_processing.workorder_id.machine_tool_name,
|
|
'RfidCode': None,
|
|
'ToolId': cnc_processing.cutting_tool_no
|
|
}
|
|
kw = json.dumps(val, ensure_ascii=False)
|
|
r = requests.post(strurl, json={}, data={'kw': kw, 'token': token}, headers=headers)
|
|
ret = r.json()
|
|
if r == 200:
|
|
return "MES装刀指令发送成功"
|
|
else:
|
|
raise ValidationError("MES装刀指令发送失败")
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals):
|
|
obj = super(CNCprocessing, self).create(vals)
|
|
# 调用CAM工单程序用刀计划创建方法
|
|
self.env['sf.cam.work.order.program.knife.plan'].create_cam_work_plan(obj)
|
|
return obj
|
|
|
|
|
|
class MrpWorkCenter(models.Model):
|
|
_inherit = 'mrp.workcenter'
|
|
|
|
def action_tool_order(self):
|
|
action = self.env.ref('sf_tool_management.sf_functional_tool_assembly_view_act')
|
|
result = action.read()[0]
|
|
return result
|