优化代码,恢复屏蔽代码,准备去测试新的NC下发
This commit is contained in:
@@ -41,20 +41,6 @@ class FtpButton(models.Model):
|
||||
else:
|
||||
workorder.user_permissions = False
|
||||
|
||||
def pri(self):
|
||||
"""
|
||||
一个测试函数,用于检测能否从”获取cnc程序“处获得NC代码文件
|
||||
:return:
|
||||
"""
|
||||
s = self.cnc_id
|
||||
s1 = self.cnc_id._filestore()
|
||||
print(s1)
|
||||
v = self.cnc_id.display_name
|
||||
a = self.cnc_id.datas
|
||||
print(v)
|
||||
print(a)
|
||||
ftp_operate.FtpController.prin(self)
|
||||
|
||||
def up(self):
|
||||
"""
|
||||
此函数用于将NC代码下发到机床
|
||||
@@ -63,37 +49,34 @@ class FtpButton(models.Model):
|
||||
# 点击下发按钮自动补偿三元检测偏差值
|
||||
|
||||
try:
|
||||
# try:
|
||||
# if self.sequence_number == '1':
|
||||
# self.check_compensation_before_up()
|
||||
# except Exception:
|
||||
# raise UserError("补偿值写入执行超时,请检查机床状态或者写入状态")
|
||||
#
|
||||
# # 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
|
||||
# remote_path = self.workorder_id.workcenter_id.machine_tool_id.ftp_remote_path
|
||||
# print(host, port, username, pwd, remote_path)
|
||||
# ftp = ftp_operate.FtpController(host, port, username, pwd)
|
||||
# # ftp.delAllfile('C://Users//马广威//Desktop//ftp')
|
||||
try:
|
||||
if self.sequence_number == '1':
|
||||
self.check_compensation_before_up()
|
||||
except Exception:
|
||||
raise UserError("补偿值写入执行超时,请检查机床状态或者写入状态")
|
||||
|
||||
# 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
|
||||
remote_path = self.workorder_id.workcenter_id.machine_tool_id.ftp_remote_path
|
||||
print(host, port, username, pwd, remote_path)
|
||||
ftp = ftp_operate.FtpController(host, port, username, pwd)
|
||||
# ftp.delAllfile('C://Users//马广威//Desktop//ftp')
|
||||
a = self.cnc_id
|
||||
# _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_remote = '{}\{}'.format('//M80(192,168,2,142)//DS', a.display_name)
|
||||
# file_path_remote = '{}\{}'.format(remote_path, 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================")
|
||||
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_remote = '{}\{}'.format('//M80(192,168,2,142)//DS', a.display_name)
|
||||
file_path_remote = '{}\{}'.format(remote_path, a.display_name)
|
||||
|
||||
with open(file_path_local, mode='wb+') as file:
|
||||
file.write(datas)
|
||||
# 存在本地的文件下发到机床
|
||||
ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
|
||||
_logger.info("======%s下发成功======" % a.display_name)
|
||||
up_time = str(datetime.now())
|
||||
|
||||
self.env['delivery.record'].create({
|
||||
@@ -274,6 +257,7 @@ class WorkCenterBarcode(models.Model):
|
||||
此函数用于将NC代码全部下发到机床
|
||||
:return:
|
||||
"""
|
||||
# 一键下发前删除机床上的全部程序
|
||||
# try:
|
||||
# filepath = '/nc2machine'
|
||||
# del_list = os.listdir(filepath)
|
||||
@@ -285,41 +269,36 @@ class WorkCenterBarcode(models.Model):
|
||||
# except Exception as e:
|
||||
# _logger.info("=====================================", e)
|
||||
# raise UserError('程序删除失败,请重试')
|
||||
# # host="192.168.2.158", port=8080, username="MITSUBISHI", password="CNC"
|
||||
# host="192.168.2.158", port=8080, username="MITSUBISHI", password="CNC"
|
||||
sequence_collect = []
|
||||
# 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
|
||||
# remote_path = self.workcenter_id.machine_tool_id.ftp_remote_path
|
||||
# print(host, port, username, pwd, remote_path)
|
||||
# ftp = ftp_operate.FtpController(host, port, username, pwd)
|
||||
# # ftp.delAllfile('C://Users//马广威//Desktop//ftp')
|
||||
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
|
||||
remote_path = self.workcenter_id.machine_tool_id.ftp_remote_path
|
||||
print(host, port, username, pwd, remote_path)
|
||||
ftp = ftp_operate.FtpController(host, port, username, pwd)
|
||||
try:
|
||||
for item in self.cnc_ids:
|
||||
a = item.cnc_id
|
||||
print(a.display_name)
|
||||
sequence_collect.append(item.sequence_number)
|
||||
# _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)
|
||||
# file_path_remote = '{}\{}'.format(remote_path, 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)
|
||||
# item.button_state = True
|
||||
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)
|
||||
file_path_remote = '{}\{}'.format(remote_path, a.display_name)
|
||||
|
||||
with open(file_path_local, mode='wb+') as file:
|
||||
file.write(datas)
|
||||
# 存在本地的文件下发到机床
|
||||
ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
|
||||
_logger.info("======%s下发成功======" % a.display_name)
|
||||
item.button_state = True
|
||||
# 增加一键下发记录
|
||||
up_time = str(datetime.now())
|
||||
sequence_str = ','.join(sequence_collect)
|
||||
|
||||
self.delivery_records.create({
|
||||
'delivery_type': '一键下发',
|
||||
'delivery_time': up_time,
|
||||
@@ -329,8 +308,6 @@ class WorkCenterBarcode(models.Model):
|
||||
except Exception as e:
|
||||
_logger.info("=====================================", e)
|
||||
raise UserError('NC下发执行超时, 请检查下发状态')
|
||||
# # 下发都执行完毕后,按钮标志位变为true
|
||||
# self.cnc_ids.button_state = True
|
||||
|
||||
def get__state(self):
|
||||
pay_time = str(datetime.now())
|
||||
@@ -342,34 +319,17 @@ class WorkCenterBarcode(models.Model):
|
||||
'state': '待付款',
|
||||
# 'pay_time': pay_time,
|
||||
# 'get_order_sf': 21,
|
||||
|
||||
},
|
||||
}
|
||||
# res_str = json.dumps(vals)
|
||||
url = 'https://bfm.cs.jikimo.com/api/get/state'
|
||||
requests.post(url, json=json, data=None)
|
||||
|
||||
def process_control(self):
|
||||
|
||||
if self.routing_type == '获取CNC加工程序' and self.state == '进行中':
|
||||
json = {
|
||||
'params': {
|
||||
'model_name': 'jikimo.process.order',
|
||||
'field_name': 'name',
|
||||
'default_code': 'PO-2022-1123-0014',
|
||||
'state': '加工中',
|
||||
},
|
||||
}
|
||||
url = 'https://bfm.cs.jikimo.com/api/get/state'
|
||||
requests.post(url, json=json, data=None)
|
||||
|
||||
|
||||
|
||||
class DeliveryRecord(models.Model):
|
||||
"""
|
||||
扫码托盘码可查到制造订单,由制造订单查工单
|
||||
"""
|
||||
# _inherit = "mrp.workorder"
|
||||
_name = "delivery.record"
|
||||
|
||||
delivery_type = fields.Char(string='下发方式', readonly=True)
|
||||
@@ -378,7 +338,6 @@ class DeliveryRecord(models.Model):
|
||||
workorder_id = fields.Many2one('mrp.workorder', string='工单')
|
||||
sf_cnc_processing_id = fields.Many2one('sf.cnc.processing', string='NC')
|
||||
|
||||
|
||||
# @api.model
|
||||
# def create(self, values):
|
||||
# try:
|
||||
@@ -391,4 +350,3 @@ class DeliveryRecord(models.Model):
|
||||
# return super().create(values)
|
||||
# except:
|
||||
# raise Exception('b_purchase_order.py:create()')
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ class UpSelectWizard(models.TransientModel):
|
||||
username = self.workcenter_id.machine_tool_id.ftp_num
|
||||
pwd = self.workcenter_id.machine_tool_id.ftp_pwd
|
||||
remote_path = self.workcenter_id.machine_tool_id.ftp_remote_path
|
||||
# print(host, port, username, pwd, remote_path)
|
||||
# ftp = ftp_operate.FtpController(host, port, username, pwd)
|
||||
print(host, port, username, pwd, remote_path)
|
||||
ftp = ftp_operate.FtpController(host, port, username, pwd)
|
||||
sequence_collect = []
|
||||
try:
|
||||
# 给文件名
|
||||
@@ -48,24 +48,25 @@ class UpSelectWizard(models.TransientModel):
|
||||
sequence_collect.append(item.sequence_number)
|
||||
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_local = '{}/{}'.format('/nc2machine', final_name)
|
||||
#
|
||||
# # 本地测试合并下发
|
||||
# # file_path_local = '{}/{}'.format('D:\\jikimo', a.display_name)
|
||||
# # file_path_remote = '{}\{}'.format('//M80(192,168,2,142)//DS', a.display_name)
|
||||
# file_path_remote = '{}\{}'.format(remote_path, final_name)
|
||||
# # 合并文件
|
||||
# with open(file_path_local, mode='ab+') as file:
|
||||
# file.write(datas)
|
||||
#
|
||||
# # 存在本地的文件下发到机床
|
||||
# _logger.info("==========存在服务器成功,准备下发===========")
|
||||
# # ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
|
||||
# # # 下发成功标识
|
||||
# # item.button_state = True
|
||||
_logger.info(a.public)
|
||||
_logger.info(a.display_name)
|
||||
datas = base64.standard_b64decode(a.datas)
|
||||
file_path_local = '{}/{}'.format('/nc2machine', final_name)
|
||||
|
||||
# 本地测试合并下发
|
||||
# file_path_local = '{}/{}'.format('D:\\jikimo', a.display_name)
|
||||
# file_path_remote = '{}\{}'.format('//M80(192,168,2,142)//DS', a.display_name)
|
||||
file_path_remote = '{}\{}'.format(remote_path, final_name)
|
||||
# 合并文件
|
||||
with open(file_path_local, mode='ab+') as file:
|
||||
file.write(datas)
|
||||
|
||||
# 存在本地的文件下发到机床
|
||||
_logger.info("==========存在服务器成功,准备下发===========")
|
||||
ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
|
||||
_logger.info("======%s下发成功======" % a.display_name)
|
||||
# 下发成功标识
|
||||
item.button_state = True
|
||||
up_time = str(datetime.now())
|
||||
sequence_str = ','.join(sequence_collect)
|
||||
self.workorder_id.delivery_records.create({
|
||||
@@ -78,91 +79,3 @@ class UpSelectWizard(models.TransientModel):
|
||||
_logger.info("=====================================", e)
|
||||
raise UserError('NC下发执行超时, 请检查下发状态')
|
||||
|
||||
# cnc_id1 = fields.Many2one('ir.attachment', compute='_compute_cnc_id')
|
||||
# sequence_number1 = fields.Char('序号', compute='_compute_cnc_id', default='0')
|
||||
# program_name1 = fields.Char('程序名', compute='_compute_cnc_id')
|
||||
# cutting_tool_name1 = fields.Char('刀具名称', compute='_compute_cnc_id')
|
||||
# cutting_tool_no1 = fields.Char('刀号', compute='_compute_cnc_id')
|
||||
# processing_type1 = fields.Char('加工类型', compute='_compute_cnc_id')
|
||||
# margin_x_y1 = fields.Char('余量_X/Y', compute='_compute_cnc_id')
|
||||
# margin_z1 = fields.Char('余量_Z', compute='_compute_cnc_id')
|
||||
# depth_of_processing_z1 = fields.Char('加工深度(Z)', compute='_compute_cnc_id')
|
||||
# cutting_tool_extension_length1 = fields.Char('刀具伸出长度', compute='_compute_cnc_id')
|
||||
# cutting_tool_handle_type1 = fields.Char('刀柄型号', compute='_compute_cnc_id')
|
||||
# estimated_processing_time1 = fields.Char('预计加工时间', compute='_compute_cnc_id')
|
||||
# remark1 = fields.Text('备注', compute='_compute_cnc_id')
|
||||
# cnc_id = fields.Many2one('sf.cnc.processing', '工单')
|
||||
# num = fields.Integer('索引', default=0)
|
||||
# cnc_id1 = fields.Many2one('ir.attachment')
|
||||
# sequence_number1 = fields.Char('序号', compute='_compute_cnc_id', default='1')
|
||||
# program_name1 = fields.Char('程序名')
|
||||
# cutting_tool_name1 = fields.Char('刀具名称')
|
||||
# cutting_tool_no1 = fields.Char('刀号')
|
||||
# processing_type1 = fields.Char('加工类型')
|
||||
# margin_x_y1 = fields.Char('余量_X/Y')
|
||||
# margin_z1 = fields.Char('余量_Z')
|
||||
# depth_of_processing_z1 = fields.Char('加工深度(Z)')
|
||||
# cutting_tool_extension_length1 = fields.Char('刀具伸出长度')
|
||||
# cutting_tool_handle_type1 = fields.Char('刀柄型号')
|
||||
# estimated_processing_time1 = fields.Char('预计加工时间')
|
||||
# remark1 = fields.Text('备注')
|
||||
# cnc_id = fields.Many2one('sf.cnc.processing', '工单')
|
||||
# num = fields.Integer('索引', default=0)
|
||||
# print(11111111111111111111111111111111111111111111111)
|
||||
# # @api.depends('program_ids')
|
||||
# def _compute_cnc_id(self):
|
||||
# print(222222222222222222222222222222222222222222)
|
||||
# workorder_id = self.env.context.get('default_workorder_id')
|
||||
# workorder = self.env['mrp.workorder'].sudo().search([('id', '=', workorder_id)])
|
||||
# # self.workcenter_id = workorder.workcent_id
|
||||
# print(workorder_id)
|
||||
#
|
||||
# lines = []
|
||||
# print(lines)
|
||||
# for item in workorder.cnc_ids:
|
||||
# # lines.append((4,item.id,0))
|
||||
# lines.append((4, item.id, 0))
|
||||
# print(lines)
|
||||
#
|
||||
# # print(self.cnc_id1, self.sequence_number1, self.program_name1, self.processing_type1,
|
||||
# # self.cutting_tool_handle_type1
|
||||
# # , self.cutting_tool_extension_length1, self.margin_z1, self.margin_z1, self.depth_of_processing_z1,
|
||||
# # self.cutting_tool_no1, self.cutting_tool_name1, self.estimated_processing_time1, self.remark1)
|
||||
# # else:
|
||||
# # self.write({
|
||||
# #
|
||||
# # # 'cnc_id1': item.cnc_id or '',
|
||||
# # # 'sequence_number1': item.sequence_number or '',
|
||||
# # # 'program_name1': item.program_name or '',
|
||||
# # # 'cutting_tool_name1': item.cutting_tool_name or '',
|
||||
# # # 'cutting_tool_no1': item.cutting_tool_no or '',
|
||||
# # # 'processing_type1': item.processing_type or '',
|
||||
# # # 'margin_x_y1': item.margin_x_y or '',
|
||||
# # # 'margin_z1': item.margin_z or '',
|
||||
# # # 'depth_of_processing_z1': item.depth_of_processing_z or '',
|
||||
# # # 'cutting_tool_extension_length1': item.cutting_tool_extension_length or '',
|
||||
# # # 'cutting_tool_handle_type1': item.cutting_tool_handle_type or '',
|
||||
# # # 'estimated_processing_time1': item.estimated_processing_time or '',
|
||||
# # # 'remark1': item.remark or '',
|
||||
# # 'id': item.sequence_number,
|
||||
# # 'cnc_id1': item.cnc_id,
|
||||
# # 'sequence_number1': item.sequence_number,
|
||||
# # 'program_name1': item.program_name,
|
||||
# # 'cutting_tool_name1': item.cutting_tool_name,
|
||||
# # 'cutting_tool_no1': item.cutting_tool_no,
|
||||
# # 'processing_type1': item.processing_type,
|
||||
# # 'margin_x_y1': item.margin_x_y,
|
||||
# # 'margin_z1': item.margin_z,
|
||||
# # 'depth_of_processing_z1': item.depth_of_processing_z,
|
||||
# # 'cutting_tool_extension_length1': item.cutting_tool_extension_length,
|
||||
# # 'cutting_tool_handle_type1': item.cutting_tool_handle_type,
|
||||
# # 'estimated_processing_time1': item.estimated_processing_time,
|
||||
# # 'remark1': item.remark,
|
||||
# # })
|
||||
# # print(self.cnc_id1, self.sequence_number1, self.program_name1, self.processing_type1,
|
||||
# # self.cutting_tool_handle_type1
|
||||
# # , self.cutting_tool_extension_length1, self.margin_z1, self.margin_z1,
|
||||
# # self.depth_of_processing_z1,
|
||||
# # self.cutting_tool_no1, self.cutting_tool_name1, self.estimated_processing_time1, self.remark1)
|
||||
#
|
||||
# self.update({'program_ids': lines})
|
||||
|
||||
Reference in New Issue
Block a user