优化代码-设置按钮权限等
This commit is contained in:
@@ -24,6 +24,23 @@ class FtpButton(models.Model):
|
||||
_inherit = 'sf.cnc.processing'
|
||||
|
||||
button_state = fields.Boolean(string='是否已经下发')
|
||||
user_permissions = fields.Boolean(string='权限', related='workorder_id.user_permissions')
|
||||
state = fields.Selection(string='状态', related='workorder_id.state')
|
||||
|
||||
@api.onchange('users_ids')
|
||||
def get_user_permissions(self):
|
||||
uid = self.env.uid
|
||||
for workorder in self:
|
||||
if workorder.users_ids:
|
||||
list_user_id = []
|
||||
for item in workorder.users_ids:
|
||||
list_user_id.append(item.id)
|
||||
if uid in list_user_id:
|
||||
workorder.user_permissions = True
|
||||
else:
|
||||
workorder.user_permissions = False
|
||||
else:
|
||||
workorder.user_permissions = False
|
||||
|
||||
def pri(self):
|
||||
"""
|
||||
@@ -53,7 +70,13 @@ class FtpButton(models.Model):
|
||||
except Exception:
|
||||
raise UserError("补偿值写入执行超时,请检查机床状态或者写入状态")
|
||||
|
||||
ftp = ftp_operate.FtpController()
|
||||
# host="192.168.2.158", port=8080, username="MITSUBISHI", password="CNC"
|
||||
host = self.workorder_id.workcenter_id.machine_tool_id.ftp_host
|
||||
port = self.workorder_id.workcenter_id.machine_tool_id.ftp_port
|
||||
username = self.workorder_id.workcenter_id.machine_tool_id.ftp_num
|
||||
pwd = self.workorder_id.workcenter_id.machine_tool_id.ftp_pwd
|
||||
|
||||
ftp = ftp_operate.FtpController(host, port, username, pwd)
|
||||
# ftp.delAllfile('C://Users//马广威//Desktop//ftp')
|
||||
a = self.cnc_id
|
||||
_logger.info(a.public)
|
||||
@@ -62,12 +85,14 @@ class FtpButton(models.Model):
|
||||
|
||||
# file_path = '{}\{}\{}'.format(a._filestore(), a.store_fname.split('/'[0]), a.display_name)
|
||||
file_path_local = '{}/{}'.format('/nc2machine', a.display_name)
|
||||
file_path_remote = '{}\{}'.format('//(192,168,2,141)//DS', a.display_name)
|
||||
file_path_remote = '{}\{}'.format('//M80(192,168,2,142)//DS', a.display_name)
|
||||
|
||||
with open(file_path_local, mode='wb+') as file:
|
||||
file.write(datas)
|
||||
# 存在本地的文件下发到机床
|
||||
_logger.info("=====================11================")
|
||||
ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
|
||||
_logger.info("=====================22================")
|
||||
except Exception as e:
|
||||
_logger.info("=====================================", e)
|
||||
raise UserError('NC下发执行超时, 请检查下发状态')
|
||||
@@ -84,6 +109,41 @@ class FtpButton(models.Model):
|
||||
# 'type': 'ir.actions.act_window',
|
||||
# 'target': 'new'
|
||||
# }
|
||||
# def up_all(self):
|
||||
# """
|
||||
# 此函数用于将NC代码全部下发到机床
|
||||
# :return:
|
||||
# """
|
||||
# # host="192.168.2.158", port=8080, username="MITSUBISHI", password="CNC"
|
||||
# host = self.workorder_id.workcenter_id.machine_tool_id.ftp_host
|
||||
# port = self.workorder_id.workcenter_id.machine_tool_id.ftp_port
|
||||
# username = self.workorder_id.workcenter_id.machine_tool_id.ftp_num
|
||||
# pwd = self.workorder_id.workcenter_id.machine_tool_id.ftp_pwd
|
||||
#
|
||||
# ftp = ftp_operate.FtpController(host, port, username, pwd)
|
||||
# # ftp.delAllfile('C://Users//马广威//Desktop//ftp')
|
||||
# for item in self.cnc_ids:
|
||||
# a = item.cnc_id
|
||||
# print(a.display_name)
|
||||
# # _logger.info(a.public)
|
||||
# # _logger.info(a.display_name)
|
||||
# # datas = base64.standard_b64decode(a.datas)
|
||||
# #
|
||||
# # # file_path = '{}\{}\{}'.format(a._filestore(), a.store_fname.split('/'[0]), a.display_name)
|
||||
# # # file_path_local = '{}/{}'.format('/nc2machine', a.display_name)
|
||||
# # file_path_local = '{}/{}'.format('D:\\jikimo', a.display_name)
|
||||
# # # file_path_remote = '{}\{}'.format('//M80(192,168,2,142)//DS', a.display_name)
|
||||
# #
|
||||
# # with open(file_path_local, mode='wb+') as file:
|
||||
# # file.write(datas)
|
||||
# # 存在本地的文件下发到机床
|
||||
# # _logger.info("=====================11================")
|
||||
# # ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
|
||||
# # _logger.info("=====================22================")
|
||||
# # except Exception as e:
|
||||
# # _logger.info("=====================================", e)
|
||||
# # raise UserError('NC下发执行超时, 请检查下发状态')
|
||||
|
||||
|
||||
def check_compensation_before_up(self):
|
||||
"""
|
||||
@@ -93,9 +153,9 @@ class FtpButton(models.Model):
|
||||
try:
|
||||
temp_dict = {}
|
||||
temp_dict[
|
||||
'ns=1;s=Project_Default.Group1.Mitsubishi_NC2.hongbianliang550'] = self.workorder_id.compensation_value_x
|
||||
'ns=1;s=Project_Default.Group1.Mitsubishi_NC.hongbianliang550'] = self.workorder_id.compensation_value_x
|
||||
temp_dict[
|
||||
'ns=1;s=Project_Default.Group1.Mitsubishi_NC2.hongbianliang551'] = self.workorder_id.compensation_value_y
|
||||
'ns=1;s=Project_Default.Group1.Mitsubishi_NC.hongbianliang551'] = self.workorder_id.compensation_value_y
|
||||
temp = py2opcua.Py2opcua()
|
||||
# temp.connect()
|
||||
temp.write(temp_dict)
|
||||
@@ -111,6 +171,21 @@ class Machine_ftp(models.Model):
|
||||
"""
|
||||
_inherit = 'sf.machine_tool'
|
||||
|
||||
workorder_ids = fields.One2many('mrp.workorder', 'machine_tool_id', string='工单')
|
||||
|
||||
# 机床配置项目
|
||||
# ftp相关
|
||||
ftp_num = fields.Char('ftp账号')
|
||||
ftp_pwd = fields.Char('ftp密码')
|
||||
ftp_host = fields.Char('ftp地址')
|
||||
ftp_port = fields.Integer('ftp端口')
|
||||
# 补偿值写入相关
|
||||
x_compensation_node = fields.Char('x补偿值节点')
|
||||
y_compensation_node = fields.Char('y补偿值节点')
|
||||
# 数采配置相关
|
||||
machine_ip = fields.Char('机床IP')
|
||||
|
||||
# 机床采集项目
|
||||
timestamp = fields.Datetime('时间戳', readonly=True)
|
||||
signed = fields.Integer('刷新间隔', readonly=True)
|
||||
status = fields.Boolean('在线状态', readonly=True)
|
||||
@@ -160,25 +235,63 @@ class WorkCenterBarcode(models.Model):
|
||||
compensation_value_x = fields.Float(string='X轴补偿值')
|
||||
compensation_value_y = fields.Float(string='Y轴补偿值')
|
||||
button_compensation_state = fields.Boolean(string='是否已经补偿')
|
||||
machine_tool_id = fields.Many2one('sf.machine_tool', string='机床')
|
||||
|
||||
def compensation(self):
|
||||
"""
|
||||
将节点与其值放入字典,字典作为参数传入
|
||||
:return:
|
||||
"""
|
||||
|
||||
hongbianliang550 = self.workcenter_id.machine_tool_id.x_compensation_node
|
||||
hongbianliang551 = self.workcenter_id.machine_tool_id.y_compensation_node
|
||||
|
||||
try:
|
||||
temp_dict = {}
|
||||
temp_dict['ns=1;s=Project_Default.Group1.Mitsubishi_NC2.hongbianliang550'] = self.compensation_value_x
|
||||
temp_dict['ns=1;s=Project_Default.Group1.Mitsubishi_NC2.hongbianliang551'] = self.compensation_value_y
|
||||
temp = py2opcua.Py2opcua()
|
||||
# temp.connect()
|
||||
temp.write(temp_dict)
|
||||
self.button_compensation_state = True
|
||||
temp_dict[hongbianliang550] = self.compensation_value_x
|
||||
temp_dict[hongbianliang551] = self.compensation_value_y
|
||||
print("=================================")
|
||||
print(temp_dict)
|
||||
# temp = py2opcua.Py2opcua()
|
||||
# # temp.connect()
|
||||
# temp.write(temp_dict)
|
||||
# self.button_compensation_state = True
|
||||
# temp.disconnect()
|
||||
except Exception as e:
|
||||
_logger.info("=====================================", e)
|
||||
raise UserError('补偿值获取失败,或机床未连接,请检查')
|
||||
|
||||
def up_all(self):
|
||||
"""
|
||||
此函数用于将NC代码全部下发到机床
|
||||
:return:
|
||||
"""
|
||||
# host="192.168.2.158", port=8080, username="MITSUBISHI", password="CNC"
|
||||
host = self.workcenter_id.machine_tool_id.ftp_host
|
||||
port = self.workcenter_id.machine_tool_id.ftp_port
|
||||
username = self.workcenter_id.machine_tool_id.ftp_num
|
||||
pwd = self.workcenter_id.machine_tool_id.ftp_pwd
|
||||
print(host, port, username, pwd)
|
||||
# ftp = ftp_operate.FtpController(host, port, username, pwd)
|
||||
# ftp.delAllfile('C://Users//马广威//Desktop//ftp')
|
||||
for item in self.cnc_ids:
|
||||
a = item.cnc_id
|
||||
print(a.display_name)
|
||||
_logger.info(a.public)
|
||||
_logger.info(a.display_name)
|
||||
datas = base64.standard_b64decode(a.datas)
|
||||
|
||||
# file_path = '{}\{}\{}'.format(a._filestore(), a.store_fname.split('/'[0]), a.display_name)
|
||||
# file_path_local = '{}/{}'.format('/nc2machine', a.display_name)
|
||||
file_path_local = '{}/{}'.format('D:\\jikimo', a.display_name)
|
||||
# file_path_remote = '{}\{}'.format('//M80(192,168,2,142)//DS', a.display_name)
|
||||
|
||||
with open(file_path_local, mode='wb+') as file:
|
||||
file.write(datas)
|
||||
# 存在本地的文件下发到机床
|
||||
# _logger.info("=====================11================")
|
||||
# ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
|
||||
# _logger.info("=====================22================")
|
||||
# except Exception as e:
|
||||
# _logger.info("=====================================", e)
|
||||
# raise UserError('NC下发执行超时, 请检查下发状态')
|
||||
|
||||
def get__state(self):
|
||||
pay_time = str(datetime.now())
|
||||
json = {
|
||||
|
||||
@@ -45,6 +45,9 @@ class FtpController:
|
||||
self.port = port
|
||||
self.username = username
|
||||
self.password = password
|
||||
# 测试
|
||||
print("==============================================")
|
||||
print(self.username, self.port, self.host, self.password)
|
||||
ftp = FTP_P()
|
||||
# self.ftp.set_debuglevel(2) #打开调试级别2,显示详细信息
|
||||
ftp.set_pasv(0) # 0主动模式 1 #被动模式
|
||||
@@ -68,7 +71,7 @@ class FtpController:
|
||||
:param localpath:
|
||||
:return:
|
||||
"""
|
||||
bufsize = 1024
|
||||
bufsize = 8192
|
||||
# fp = open(localpath, 'rb')
|
||||
# self.ftp.storbinary('STOR ' + remotepath, fp, bufsize)
|
||||
# fp.close()
|
||||
|
||||
Reference in New Issue
Block a user