Accept Merge Request #853: (feature/中控接口优化1 -> develop)
Merge Request: 优化中控接口 Created By: @禹翔辉 Reviewed By: @马广威 Approved By: @马广威 Accepted By: @禹翔辉 URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/853
This commit is contained in:
@@ -1,34 +1,36 @@
|
||||
import json
|
||||
import requests
|
||||
import logging
|
||||
from odoo import fields, models, api
|
||||
from odoo.exceptions import ValidationError
|
||||
from datetime import datetime
|
||||
from odoo.addons.sf_base.commons.common import Common
|
||||
|
||||
|
||||
class QualityCheck(models.Model):
|
||||
_inherit = "quality.check"
|
||||
_description = '零件特采'
|
||||
|
||||
# ==========零件特采接口==========
|
||||
def _register_tool_groups(self):
|
||||
create_url = '/AutoDeviceApi/PartSpecProc'
|
||||
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 = {
|
||||
'RfidCode': None,
|
||||
}
|
||||
kw = json.dumps(val, ensure_ascii=False)
|
||||
r = requests.post(strurl, json={}, data={'kw': kw, 'token': token}, headers=headers)
|
||||
def _register_quality_check(self):
|
||||
# create_url = '/AutoDeviceApi/PartSpecProc'
|
||||
# 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/PartSpecProc"
|
||||
val = ['0037835872']
|
||||
r = requests.post(crea_url, json=val, headers=headers)
|
||||
ret = r.json()
|
||||
if r == 200:
|
||||
logging.info('_register_quality_check:%s' % ret)
|
||||
if ret['Succeed']:
|
||||
return "零件特采发送成功"
|
||||
else:
|
||||
raise ValidationError("零件特采发送失败")
|
||||
|
||||
# @api.onchange('quality_state')
|
||||
# def _onchange_quality_state(self):
|
||||
# if self.quality_state in ['pass', 'fail']:
|
||||
# self._register_tool_groups()
|
||||
def do_fail(self):
|
||||
self.write({
|
||||
'quality_state': 'fail',
|
||||
'user_id': self.env.user.id,
|
||||
'control_date': datetime.now()})
|
||||
self._register_quality_check()
|
||||
|
||||
@@ -8,54 +8,6 @@ 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/ToolGroup', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
|
||||
cors="*")
|
||||
def get_functional_tool_groups_Info(self, **kw):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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装刀指令发送失败")
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<button string="获取机床刀库信息" name="register_equipment_tool" type="object" class="btn-primary"/>
|
||||
<field name='product_template_ids'>
|
||||
<tree editable='bottom'>
|
||||
<field name="code"/>
|
||||
<field name="code" readonly="false"/>
|
||||
<field name="tool_code"/>
|
||||
<field name="functional_tool_type"/>
|
||||
<field name="functional_tool_name_id"/>
|
||||
|
||||
@@ -812,6 +812,8 @@
|
||||
attrs="{'invisible': [('plan_execute_status', '!=', '0')]}" confirm="是否确认申请装刀"/>
|
||||
<button string="撤回" name="revocation" type="object" class="btn-primary"
|
||||
attrs="{'invisible': [('plan_execute_status', '!=', '1')]}" confirm="是否确认撤回装刀"/>
|
||||
<button string="发起中控装刀" name="knife_plan_cnc_processing" type="object" class="btn-primary"
|
||||
attrs="{'invisible': [('plan_execute_status', '!=', '2')]}"/>
|
||||
<field name="plan_execute_status" widget="statusbar" statusbar_visible="0,1,2"/>
|
||||
</header>
|
||||
|
||||
@@ -827,7 +829,7 @@
|
||||
<field name="filename"/>
|
||||
<field name="production_line_id"/>
|
||||
<field name="machine_table_name_id" string="机台号"/>
|
||||
<field name="cam_cutter_spacing_code"/>
|
||||
<field name="cutter_spacing_code_id"/>
|
||||
<field name="tool_position_interface_type"/>
|
||||
<field name="sf_functional_tool_assembly_id" string="组装单"/>
|
||||
</group>
|
||||
@@ -1040,7 +1042,7 @@
|
||||
<group>
|
||||
<group>
|
||||
<field name="barcode_id" invisible="True"/>
|
||||
<field name="rfid" string="功能刀具rfid"/>
|
||||
<field name="rfid" string="功能刀具rfid" readonly="false"/>
|
||||
<field name="code"/>
|
||||
<field name="after_assembly_functional_tool_name"
|
||||
string="功能刀具名称"/>
|
||||
|
||||
@@ -389,7 +389,7 @@ class ShelfLocation(models.Model):
|
||||
# record.location_status = '空闲'
|
||||
|
||||
|
||||
#调取获取货位信息接口
|
||||
# 调取获取货位信息接口
|
||||
def get_sf_shelf_location_info(self):
|
||||
# sf_sync_config = self.env['res.config.settings'].get_values()
|
||||
# token = sf_sync_config['token']
|
||||
@@ -401,7 +401,9 @@ class ShelfLocation(models.Model):
|
||||
# objs_all = self.env['maintenance.equipment'].search([('id', '=', self.id)])
|
||||
# machine_tool_list = []
|
||||
|
||||
r = requests.get(crea_url, headers=headers)
|
||||
params = {'DeviceId': 'Cabinet-AL'}
|
||||
r = requests.get(crea_url, params=params, headers=headers)
|
||||
|
||||
ret = r.json()
|
||||
|
||||
print(ret)
|
||||
|
||||
Reference in New Issue
Block a user