From 2c81aaab1f4095ed88c2638bfb4e02c303456ded Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Thu, 16 Mar 2023 20:24:44 +0800
Subject: [PATCH 1/9] =?UTF-8?q?=E4=B8=80=E9=94=AE=E5=90=88=E5=B9=B6?=
=?UTF-8?q?=E4=B8=8B=E5=8F=91=E5=8A=9F=E8=83=BD=E5=9F=BA=E6=9C=AC=E5=AE=9E?=
=?UTF-8?q?=E7=8E=B0=EF=BC=8C=E4=B8=8B=E4=B8=80=E6=AD=A5=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=E6=89=AB=E7=A0=81=E4=B8=80=E9=94=AE=E5=90=88=E5=B9=B6=E4=B8=8B?=
=?UTF-8?q?=E5=8F=91=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_machine_connect/models/ftp_client.py | 89 +++++++++++++++++++++++
sf_machine_connect/models/ftp_operate.py | 2 +-
sf_machine_connect/views/compensation.xml | 4 +
sf_machine_connect/wizard/action_up.py | 15 +++-
4 files changed, 107 insertions(+), 3 deletions(-)
diff --git a/sf_machine_connect/models/ftp_client.py b/sf_machine_connect/models/ftp_client.py
index 9b5dda7a..08270510 100644
--- a/sf_machine_connect/models/ftp_client.py
+++ b/sf_machine_connect/models/ftp_client.py
@@ -343,6 +343,95 @@ class WorkCenterBarcode(models.Model):
_logger.info("=====================================", e)
raise UserError('NC下发执行超时, 请检查下发状态')
+ def up_merge_all(self):
+ """
+ 此函数用于将NC代码一键合并下发到机床
+ :return:
+ """
+ # 一键合并下发前删除机床上的全部程序
+ try:
+ filepath = '/nc2machine'
+ del_list = os.listdir(filepath)
+ _logger.info("=====================================%s" % del_list)
+ for f in del_list:
+ file_path = os.path.join(filepath, f)
+ if os.path.isfile(file_path):
+ os.remove(file_path)
+ except Exception as e:
+ _logger.info("=====================================", e)
+ raise UserError('程序删除失败,请重试')
+ # host="192.168.2.158", port=8080, username="MITSUBISHI", password="CNC"
+ try:
+ self.compensation()
+ except Exception:
+ raise UserError("补偿值写入执行超时,请检查机床状态或者写入状态")
+ 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
+ _logger.info("=====================1666666661111================%s,%s,%s,%s" % (host, port, username, pwd))
+ ftp = ftp_operate.FtpController(host, port, username, pwd)
+ _logger.info("=====================1777777777111================")
+ file_path_local = ''
+ file_path_remote = ''
+
+ try:
+ # 给文件名
+ _logger.info('启动')
+ begin_name1 = self.cnc_ids[0].cnc_id.display_name.split('-')
+ _logger.info(begin_name1)
+ temp_name1 = begin_name1[-1].split('.')
+ final_name = '%s-ALL-MERGE.%s' % (begin_name1[0], temp_name1[-1])
+ _logger.info(final_name)
+ for item in self.cnc_ids:
+ a = item.cnc_id
+ sequence_collect.append(item.sequence_number)
+ datas = base64.standard_b64decode(a.datas)
+ # file_path = '{}\{}\{}'.format(a._filestore(), a.store_fname.split('/'[0]), a.display_name)
+ 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)
+ item.button_state = True
+ _logger.info('========一键下发前合并成功===============')
+
+ # 去除合并文件中间部分的头尾
+ with open(file_path_local, mode='rb+') as f:
+ # _logger.info(f.read())
+ # content = f.read()
+ # _logger.info(content)
+ new_content = f.read().replace(b'\r\nM30\r\n%\r\n%\r\n', b'\r\n')
+ # _logger.info(new_content)
+ f.seek(0)
+ f.truncate()
+ f.write(new_content)
+ _logger.info('========二次合并成功===============')
+
+ # 存在本地的文件下发到机床
+ ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
+ _logger.info("======%s一键合并下发成功======" % a.display_name)
+ ftp.close_ftp()
+ # 增加一键合并下发记录
+ up_time = str(datetime.now())
+ sequence_str = ','.join(sequence_collect)
+ self.delivery_records.create({
+ 'delivery_type': '一键合并下发',
+ 'delivery_time': up_time,
+ 'influence_record': sequence_str,
+ })
+ _logger.info("=====================22================")
+ except Exception as e:
+ for item in self.cnc_ids:
+ item.button_state = False
+ _logger.info("=====================================", e)
+ raise UserError('NC下发执行超时, 请检查下发状态')
+
def get__state(self):
pay_time = str(datetime.now())
json = {
diff --git a/sf_machine_connect/models/ftp_operate.py b/sf_machine_connect/models/ftp_operate.py
index dd75ee09..277851ff 100644
--- a/sf_machine_connect/models/ftp_operate.py
+++ b/sf_machine_connect/models/ftp_operate.py
@@ -49,7 +49,7 @@ class FtpController:
self.port = port
self.username = username
self.password = password
- _logger.info("===================ftppppp==================%s,%s,%s,%s" % self.host, self.port, self.username, self.password)
+ # _logger.info("===================ftppppp==================%s,%s,%s,%s" % self.host, self.port, self.username, self.password)
# 测试
print("==============================================")
print(self.username, self.port, self.host, self.password)
diff --git a/sf_machine_connect/views/compensation.xml b/sf_machine_connect/views/compensation.xml
index 8a82ea49..4804df61 100644
--- a/sf_machine_connect/views/compensation.xml
+++ b/sf_machine_connect/views/compensation.xml
@@ -28,6 +28,10 @@
+
+
diff --git a/sf_machine_connect/wizard/action_up.py b/sf_machine_connect/wizard/action_up.py
index e72fa5ff..e7c605e7 100644
--- a/sf_machine_connect/wizard/action_up.py
+++ b/sf_machine_connect/wizard/action_up.py
@@ -73,10 +73,21 @@ class UpSelectWizard(models.TransientModel):
# 合并文件
with open(file_path_local, mode='ab+') as file:
file.write(datas)
-
# 下发成功标识
item.button_state = True
-
+ _logger.info('========初次合并成功===============')
+ _logger.info(file_path_local)
+ # 去除合并文件中间部分的头尾
+ with open(file_path_local, mode='rb+') as f:
+ # _logger.info(f.read())
+ # content = f.read()
+ # _logger.info(content)
+ new_content = f.read().replace(b'\r\nM30\r\n%\r\n%\r\n', b'\r\n')
+ # _logger.info(new_content)
+ f.seek(0)
+ f.truncate()
+ f.write(new_content)
+ _logger.info('========二次合并成功===============')
# 存在本地的文件下发到机床
_logger.info("==========存在服务器成功,准备下发===========")
ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
From 1505c565132a563d2c8ed773ac0b627afce040de Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Mon, 20 Mar 2023 15:06:59 +0800
Subject: [PATCH 2/9] =?UTF-8?q?=E6=89=AB=E7=A0=81=E6=89=A7=E8=A1=8C?=
=?UTF-8?q?=E4=B8=80=E9=94=AE=E5=90=88=E5=B9=B6=E4=B8=8B=E5=8F=91=E6=8C=89?=
=?UTF-8?q?=E9=92=AE=E5=B7=B2=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../views/SfWorkOrderBarcodes.xml | 9 ++-
sf_manufacturing/models/mrp_workorder.py | 61 +++++++++++++------
2 files changed, 51 insertions(+), 19 deletions(-)
diff --git a/sf_machine_connect/views/SfWorkOrderBarcodes.xml b/sf_machine_connect/views/SfWorkOrderBarcodes.xml
index 5507f707..fbdbc43c 100644
--- a/sf_machine_connect/views/SfWorkOrderBarcodes.xml
+++ b/sf_machine_connect/views/SfWorkOrderBarcodes.xml
@@ -3,13 +3,18 @@
sf.install.the.tray.workorder.form.scan.barcode
mrp.workorder
+
+
+
+
+
+
-
+
-
\ No newline at end of file
diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py
index 82e228a4..79bb8cad 100644
--- a/sf_manufacturing/models/mrp_workorder.py
+++ b/sf_manufacturing/models/mrp_workorder.py
@@ -561,21 +561,48 @@ class SfWorkOrderBarcodes(models.Model):
def on_barcode_scanned(self, barcode):
workorder = self.env['mrp.workorder'].browse(self.ids)
if "*" not in barcode:
- tray_code = self.env['sf.tray'].search([('code', '=', barcode)])
- self.tray_code = tray_code.code
- self.tray_id = workorder.gettray_auto(barcode)
+ if self.routing_type == '装夹':
+ tray_code = self.env['sf.tray'].search([('code', '=', barcode)])
+ self.tray_code = tray_code.code
+ self.tray_id = workorder.gettray_auto(barcode)
+ elif self.routing_type == '前置三元定位检测':
+ print('我是前置三元检测')
+ logging.info('我是前置三元检测')
+ elif self.routing_type == 'CNC加工':
+ if barcode == 'UP-ALL':
+ print("我是一键合并下发")
+ logging.info('我是一键合并下发')
+ self.up_merge_all()
+ else:
+ print('CNC加工')
+ # print(barcode)
+ # a = self.env['sf.tray'].search([('code', '=', barcode)])
+ # print(a)
+ # # workorder_obj = self.env['mrp.workorder'].search([('tray_code', '=', barcode)], limit=1)
+ # workorder_obj = self.env['mrp.workorder'].search([('tray_code', '=', barcode)])
+ # e = workorder_obj.id
+ # print(workorder_obj)
+ # action = {
+ # 'name': '工单',
+ # 'type': 'ir.actions.act_window',
+ # # 'view_type': 'form',
+ # 'view_mode': 'form',
+ # 'res_model': 'mrp.workorder',
+ # 'view_id': self.env.ref('mrp.mrp_production_workorder_form_view_inherit').id,
+ # # 'res_id': workorder_obj.id,
+ # 'res_id': 1023,
+ # 'target': 'current',
+ # # 'context': self.env.context,
+ # # 'flags': {'initial_mode': 'edit'},
+ # }
+ # return action
+
+ elif self.routing_type == '后置三元质量检测':
+ print('后置三元检测')
+ elif self.routing_type == '解除装夹':
+ print("我是解除装夹")
+ else:
+ pass
+
else:
- self.pro_code_ok = workorder.pro_code_is_ok(barcode)
-
-
-
- # return {
- # 'type': 'ir.actions.act_window',
- # 'name': '工单',
- # 'res_model': 'mrp.workorder',
- # 'view_mode': 'form',
- # 'context': {'active_id': self.id},
- # # 'target': 'current',
- # }
-
-
+ self.pro_code_ok = workorder.pro_code_is_ok(barcode)
\ No newline at end of file
From a742018956334ea45c1833dde53d344c7610a60b Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Fri, 24 Mar 2023 21:40:10 +0800
Subject: [PATCH 3/9] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=89=80=E6=9C=89?=
=?UTF-8?q?=E5=8F=AF=E9=87=87=E9=9B=86=E6=95=B0=E6=8D=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_machine_connect/models/ftp_client.py | 51 ++++++++++++++++---
.../security/ir.model.access.csv | 2 -
sf_machine_connect/views/machine_monitor.xml | 43 +++++++++++++---
sf_machine_connect/wizard/action_up.py | 3 +-
4 files changed, 81 insertions(+), 18 deletions(-)
diff --git a/sf_machine_connect/models/ftp_client.py b/sf_machine_connect/models/ftp_client.py
index 08270510..defb33dc 100644
--- a/sf_machine_connect/models/ftp_client.py
+++ b/sf_machine_connect/models/ftp_client.py
@@ -138,16 +138,49 @@ class Machine_ftp(models.Model):
machine_ip = fields.Char('机床IP')
machine_signed = fields.Char('机床刷新间隔')
machine_status = fields.Char('机床在线状态')
- machine_time_on = fields.Char('机床总在线时长')
- machine_tool_num = fields.Char('机床当前刀具')
- machine_program = fields.Char('机床当前程序')
+ machine_cnc_type = fields.Char('机床CNC型号')
+ machine_axis_count = fields.Char('机床轴总数')
machine_run_status = fields.Char('机床运行状态')
- machine_run_time = fields.Char('机床总运行时长')
- machine_cut_time = fields.Char('机床总切削时长')
- machine_cut_status = fields.Char('机床切削状态')
machine_emg_status = fields.Char('机床急停状态')
- machine_mode = fields.Char('机床操作模式')
- machine_spindle_speed = fields.Char('机床主轴转速')
+ machine_cut_status = fields.Char('机床当前切削状态')
+ machine_mode = fields.Char('机床当前操作模式')
+ machine_spindle_load = fields.Char('机床主轴负载')
+ machine_x_mach = fields.Char('机床X轴机械坐标')
+ machine_x_abs_mach = fields.Char('机床X轴当前位置')
+ machine_x_rel_mach = fields.Char('机床X轴相对工件坐标')
+ machine_x_dis_mach = fields.Char('机床X轴目标距离')
+ machine_x_axis_load = fields.Char('机床X轴伺服轴负载')
+ machine_y_mach = fields.Char('机床Y轴机械坐标')
+ machine_y_abs_mach = fields.Char('机床Y轴当前位置')
+ machine_y_rel_mach = fields.Char('机床Y轴相对工件坐标')
+ machine_y_dis_mach = fields.Char('机床Y轴目标距离')
+ machine_y_axis_load = fields.Char('机床Y轴伺服轴负载')
+ machine_z_mach = fields.Char('机床Z轴机械坐标')
+ machine_z_abs_mach = fields.Char('机床Z轴当前位置')
+ machine_z_rel_mach = fields.Char('机床Z轴相对工件坐标')
+ machine_z_dis_mach = fields.Char('机床Z轴目标距离')
+ machine_z_axis_load = fields.Char('机床Z轴伺服轴负载')
+ machine_tool_num = fields.Char('机床当前刀位号')
+ machine_program = fields.Char('机床主程序名称')
+ machine_current_prg = fields.Char('机床当前执行指令')
+ machine_prg_seq = fields.Char('机床当前执行语句号')
+ machine_spindle_speed_set = fields.Char('机床设定主轴速度')
+ machine_act_spindle_speed = fields.Char('机床实际主轴转速')
+ machine_feed_speed_set = fields.Char('机床设定进给速度')
+ machine_act_feed_speed = fields.Char('机床实际进给速度')
+ machine_spindle_feed = fields.Char('机床主轴倍率')
+ machine_feed_rate = fields.Char('机床进给倍率')
+ machine_rapid_feed = fields.Char('机床快速移动倍率')
+ machine_run_time = fields.Char('机床运行时间')
+ machine_cut_time = fields.Char('机床切削时间')
+ machine_keep_alive_time = fields.Char('机床上电时间')
+ machine_circle_time = fields.Char('机床循环时间')
+ machine_product_counts = fields.Char('机床加工件数')
+ machine_system_date = fields.Char('机床系统日期')
+ machine_system_time = fields.Char('机床系统时间')
+ machine_alarm_msg = fields.Char('机床系统报警')
+
+
# 刀位配置
tool_num1 = fields.Char('刀位1')
tool_num2 = fields.Char('刀位2')
@@ -222,6 +255,7 @@ class WorkCenterBarcode(models.Model):
"""
_inherit = "mrp.workorder"
+ # barcode = fields.Binary(string='条码', default='UP-ALL')
compensation_value_x = fields.Float(string='X轴补偿值')
compensation_value_y = fields.Float(string='Y轴补偿值')
button_compensation_state = fields.Boolean(string='是否已经补偿', readonly=True)
@@ -470,6 +504,7 @@ class DeliveryRecord(models.Model):
扫码托盘码可查到制造订单,由制造订单查工单
"""
_name = "delivery.record"
+ _description = "Delivery Record"
delivery_type = fields.Char(string='下发方式', readonly=True)
delivery_time = fields.Char(string='下发时间', readonly=True)
diff --git a/sf_machine_connect/security/ir.model.access.csv b/sf_machine_connect/security/ir.model.access.csv
index cfd49500..abbfb2de 100644
--- a/sf_machine_connect/security/ir.model.access.csv
+++ b/sf_machine_connect/security/ir.model.access.csv
@@ -1,5 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
-
access_up_select_wizard,up.select.wizard,model_up_select_wizard,base.group_user,1,1,1,1
access_delivery_record,delivery.record,model_delivery_record,base.group_user,1,1,1,1
-access_mrp_workorder,mrp.workorder,model_mrp_workorder,base.group_user,1,1,1,1
diff --git a/sf_machine_connect/views/machine_monitor.xml b/sf_machine_connect/views/machine_monitor.xml
index 30324ed5..d685ac1e 100644
--- a/sf_machine_connect/views/machine_monitor.xml
+++ b/sf_machine_connect/views/machine_monitor.xml
@@ -146,16 +146,47 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
diff --git a/sf_machine_connect/wizard/action_up.py b/sf_machine_connect/wizard/action_up.py
index e7c605e7..ef4f860c 100644
--- a/sf_machine_connect/wizard/action_up.py
+++ b/sf_machine_connect/wizard/action_up.py
@@ -18,13 +18,13 @@ _logger = logging.getLogger(__name__)
class UpSelectWizard(models.TransientModel):
_name = 'up.select.wizard'
+ _description = 'Up Select Wizard'
workorder_id = fields.Many2one('mrp.workorder', string='工单', readonly=True)
workcenter_id = fields.Many2one('mrp.workcenter', string='工作中心', related='workorder_id.workcenter_id',
readonly=True)
program_ids = fields.Many2many('sf.cnc.processing', string='程序列表')
-
def confirm_up(self):
# 合并下发前删除机床上的全部程序
try:
@@ -106,4 +106,3 @@ class UpSelectWizard(models.TransientModel):
item.button_state = False
_logger.info("=====================================", e)
raise UserError('NC下发执行超时, 请检查下发状态')
-
From d236db5dfd7b565473b0852f11ae3f7ebfdea910 Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Sun, 2 Apr 2023 22:34:29 +0800
Subject: [PATCH 4/9] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=80=E4=BD=8D?=
=?UTF-8?q?=E7=AD=89=E5=AD=97=E6=AE=B5=E5=B1=95=E7=A4=BA=E5=BD=A2=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../views/machine_info_present.xml | 34 ++-
sf_machine_connect/views/machine_monitor.xml | 278 ++++++++++--------
2 files changed, 176 insertions(+), 136 deletions(-)
diff --git a/sf_machine_connect/views/machine_info_present.xml b/sf_machine_connect/views/machine_info_present.xml
index c587b7d2..b25a3515 100644
--- a/sf_machine_connect/views/machine_info_present.xml
+++ b/sf_machine_connect/views/machine_info_present.xml
@@ -8,21 +8,29 @@
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sf_machine_connect/views/machine_monitor.xml b/sf_machine_connect/views/machine_monitor.xml
index d685ac1e..f07d784a 100644
--- a/sf_machine_connect/views/machine_monitor.xml
+++ b/sf_machine_connect/views/machine_monitor.xml
@@ -11,47 +11,62 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -126,105 +141,122 @@
-
+
-
-
+ -->
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
From baee5a975f3e808c9489820d8ab5df14defeecba Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Tue, 4 Apr 2023 11:16:01 +0800
Subject: [PATCH 5/9] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=BB=99js=E7=9A=84actio?=
=?UTF-8?q?n=E5=B7=B2=E9=85=8D=E7=BD=AE=E6=88=90=E5=8A=9F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_machine_connect/models/ftp_client.py | 53 ++++++++++++++++++++++++-
1 file changed, 52 insertions(+), 1 deletion(-)
diff --git a/sf_machine_connect/models/ftp_client.py b/sf_machine_connect/models/ftp_client.py
index defb33dc..53ff1e9e 100644
--- a/sf_machine_connect/models/ftp_client.py
+++ b/sf_machine_connect/models/ftp_client.py
@@ -7,7 +7,7 @@ import hashlib
import time
import requests
from datetime import datetime
-
+from odoo.http import request
from odoo import fields, models, api, _
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError
@@ -482,6 +482,57 @@ class WorkCenterBarcode(models.Model):
url = 'https://bfm.cs.jikimo.com/api/get/state'
requests.post(url, json=json, data=None)
+ def action_test(self, barcode=12345):
+
+ workorder_obj = self.env['mrp.workorder'].sudo().search([('tray_code', '=', barcode)])
+ action = {
+ 'name': '工单',
+ # 'name': name,
+ 'type': 'ir.actions.act_window',
+ # 'view_type': 'form',
+ 'view_mode': 'form',
+ 'res_model': 'mrp.workorder',
+ 'view_id': self.env.ref('mrp.mrp_production_workorder_form_view_inherit').id,
+ 'res_id': 1023,
+ 'target': 'current',
+ 'context': {'id': workorder_obj.id},
+ # 'flags': {'initial_mode': 'edit'},
+ }
+ return action
+ # result = request.env['ir.actions.act_window'].sudo().create(action).read()[0]
+ # action = {'action': action}
+ # return result
+
+ @api.model
+ def get_product_id_by_barcode(self, barcode, **kwargs):
+ print(kwargs)
+ print(barcode)
+ print('111111111111111111111')
+ workorder_obj = self.env['mrp.workorder'].sudo().search([('tray_code', '=', barcode)])
+ workorder_cnc = self.env['mrp.workorder'].sudo().search(['&', ('production_id', '=', workorder_obj.production_id.id), ('name', '=', 'CNC加工')])
+ print('222222222222222222222222')
+ if workorder_obj:
+ print(workorder_obj)
+ print(workorder_obj.id)
+ action = {
+ 'name': '工单',
+ 'type': 'ir.actions.act_window',
+ # 'view_type': 'form',
+ 'views': [[False, 'form']],
+ 'view_mode': 'form',
+ 'res_model': 'mrp.workorder',
+ 'view_id': request.env.ref('mrp.mrp_production_workorder_form_view_inherit').id,
+ 'res_id': workorder_cnc.id,
+ 'target': 'current',
+ 'context': {'id': workorder_obj.id},
+ # 'flags': {'initial_mode': 'edit'},
+ }
+ action = {'result': action, 'error': '返回错误'}
+ action1 = json.dumps(action)
+ return action1
+ else:
+ return False
+
class CuttingTimeToolType(models.Model):
_inherit = 'sf.cutting_tool.type'
From 6ea811afeda750e7498345b867d391eaba3fd143 Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Tue, 4 Apr 2023 15:12:33 +0800
Subject: [PATCH 6/9] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E9=80=9A=E8=BF=87?=
=?UTF-8?q?=E6=94=B9=E9=80=A0=E5=8E=9F=E7=94=9Fjs=E5=AE=9E=E7=8E=B0?=
=?UTF-8?q?=E6=89=AB=E7=A0=81=E8=B7=B3=E8=BD=ACform?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_machine_connect/models/ftp_client.py | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/sf_machine_connect/models/ftp_client.py b/sf_machine_connect/models/ftp_client.py
index 53ff1e9e..9236f86e 100644
--- a/sf_machine_connect/models/ftp_client.py
+++ b/sf_machine_connect/models/ftp_client.py
@@ -508,12 +508,14 @@ class WorkCenterBarcode(models.Model):
print(kwargs)
print(barcode)
print('111111111111111111111')
- workorder_obj = self.env['mrp.workorder'].sudo().search([('tray_code', '=', barcode)])
- workorder_cnc = self.env['mrp.workorder'].sudo().search(['&', ('production_id', '=', workorder_obj.production_id.id), ('name', '=', 'CNC加工')])
+ workorder_obj_target = self.env['mrp.workorder'].sudo().search([('tray_code', '=', barcode)])
+ workorder_obj_current = self.env['mrp.workorder'].sudo().search([('id', '=', kwargs['current_id'])])
+ # workorder_cnc = self.env['mrp.workorder'].sudo().search(['&', ('production_id', '=', workorder_obj.production_id.id), ('name', '=', 'CNC加工')])
+ workorder_cnc = self.env['mrp.workorder'].sudo().search(['&', ('production_id', '=', workorder_obj_target.production_id.id), ('name', '=', workorder_obj_current.name)])
print('222222222222222222222222')
- if workorder_obj:
- print(workorder_obj)
- print(workorder_obj.id)
+ if workorder_obj_target:
+ print(workorder_obj_target)
+ print(workorder_obj_target.id)
action = {
'name': '工单',
'type': 'ir.actions.act_window',
@@ -524,7 +526,7 @@ class WorkCenterBarcode(models.Model):
'view_id': request.env.ref('mrp.mrp_production_workorder_form_view_inherit').id,
'res_id': workorder_cnc.id,
'target': 'current',
- 'context': {'id': workorder_obj.id},
+ 'context': {'id': workorder_obj_target.id},
# 'flags': {'initial_mode': 'edit'},
}
action = {'result': action, 'error': '返回错误'}
From c2a22b5ac74a9f387e5e7b9b058dafa83eccab7d Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Wed, 12 Apr 2023 17:43:39 +0800
Subject: [PATCH 7/9] =?UTF-8?q?=E5=B9=B3=E6=9D=BF=E6=89=AB=E7=A0=81?=
=?UTF-8?q?=E7=BB=91=E5=AE=9A=E6=89=98=E7=9B=98=E5=9F=BA=E6=9C=AC=E5=AE=8C?=
=?UTF-8?q?=E6=88=90=EF=BC=8C=E4=BD=86=E8=BF=98=E5=AD=98=E5=9C=A8=E5=B0=8F?=
=?UTF-8?q?=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_machine_connect/static/src/js/test.js | 212 +++++++++++++++++++++--
1 file changed, 193 insertions(+), 19 deletions(-)
diff --git a/sf_machine_connect/static/src/js/test.js b/sf_machine_connect/static/src/js/test.js
index 1f1c1d58..9744a786 100644
--- a/sf_machine_connect/static/src/js/test.js
+++ b/sf_machine_connect/static/src/js/test.js
@@ -1,3 +1,85 @@
+// /** @odoo-module **/
+//
+// import { browser } from "@web/core/browser/browser";
+// import { Dialog } from "@web/core/dialog/dialog";
+// import { _lt } from "@web/core/l10n/translation";
+// import { useChildRef, useOwnedDialogs, useService } from "@web/core/utils/hooks";
+// import { sprintf } from "@web/core/utils/strings";
+// import { isMobileOS } from "@web/core/browser/feature_detection";
+// import * as BarcodeScanner from "@web/webclient/barcode/barcode_scanner";
+//
+// const {xml, Component} = owl;
+// import { standardFieldProps } from "@web/views/fields/standard_field_props";
+// // Import the registry
+// import {registry} from "@web/core/registry";
+//
+//
+// export class CodeField extends Component {
+// setup() {
+// super.setup();
+// }
+// async onBarcodeBtnClick() {
+// const barcode = await BarcodeScanner.scanBarcode();
+// if (barcode) {
+// await this.onBarcodeScanned(barcode);
+// if ("vibrate" in browser.navigator) {
+// browser.navigator.vibrate(100);
+// }
+// } else {
+// this.notification.add(this.env._t("Please, scan again !"), {
+// type: "warning",
+// });
+// }
+// }
+// async search(barcode) {
+// const results = await this.orm.call("sf.tray", "name_search", [code], {
+// name: barcode,
+// args: this.getDomain(),
+// operator: "ilike",
+// limit: 2, // If one result we set directly and if more than one we use normal flow so no need to search more
+// context: this.context,
+// });
+// return results.map((result) => {
+// const [id, displayName] = result;
+// return {
+// id,
+// name: displayName,
+// };
+// });
+// }
+// async onBarcodeScanned(barcode) {
+// const results = await this.search(barcode);
+// const records = results.filter((r) => !!r.id);
+// if (records.length === 1) {
+// this.update([{ id: records[0].id, name: records[0].name }]);
+// } else {
+// const searchInput = this.autocompleteContainerRef.el.querySelector("input");
+// searchInput.value = barcode;
+// searchInput.dispatchEvent(new Event("input"));
+// if (this.env.isSmall) {
+// searchInput.click();
+// }
+// }
+// }
+// }
+//
+// CodeField.template = xml`
+//
+// `;
+// // CodeField.template = 'sf_machine_connect.CodeField';
+// CodeField.props = standardFieldProps;
+//
+// // Add the field to the correct category
+// registry.category("fields").add("code", CodeField);
/** @odoo-module **/
import { browser } from "@web/core/browser/browser";
@@ -17,41 +99,125 @@ import {registry} from "@web/core/registry";
export class CodeField extends Component {
setup() {
super.setup();
+ this.orm = this.env.services.orm;
+ this.record = this.props.record;
}
- async onBarcodeBtnClick() {
+ // get domain() {
+ // return this.props.record.getFieldDomain(this.props.name);
+
+ async onBarcodeBtnClick() {
+ // console.log(BarcodeScanner)
const barcode = await BarcodeScanner.scanBarcode();
+ // console.log(typeof barcode)
+ // alert(barcode)
+
if (barcode) {
- await this.onBarcodeScanned(barcode);
+ // console.log("存在")
+ // alert('存在')
+ await this.onBarcodeScanned(barcode);
if ("vibrate" in browser.navigator) {
browser.navigator.vibrate(100);
}
} else {
+ // console.log("不存在")
+ // alert('不存在')
this.notification.add(this.env._t("Please, scan again !"), {
type: "warning",
});
}
}
async search(barcode) {
- const results = await this.orm.call("sf.tray", "name_search", [code], {
- name: barcode,
- args: this.getDomain(),
- operator: "ilike",
- limit: 2, // If one result we set directly and if more than one we use normal flow so no need to search more
- context: this.context,
- });
+ alert('我是search')
+ const domain = [["code", "=", barcode]];
+ // const domain = [];
+ console.log(domain)
+ alert('走到这里了')
+ const fields = ["id", "code", "name", "state"];
+ console.log(fields)
+ alert('走到这里了1')
+ const results = await this.orm.call("sf.tray", "search_read", [domain, fields]);
+ const values = await this.orm.call("sf.tray", "search_read", [domain]);
+ console.log(results)
+ alert('走到这里了2')
return results.map((result) => {
- const [id, displayName] = result;
- return {
- id,
- name: displayName,
- };
- });
+ return {
+ id: result.id,
+ code: result.code,
+ name: result.name,
+ state: result.state,
+ values: values,
+ };
+ });
}
async onBarcodeScanned(barcode) {
+ // alert('我是ONbarcodeScanned')
const results = await this.search(barcode);
+ console.log(results)
const records = results.filter((r) => !!r.id);
+ console.log(records)
if (records.length === 1) {
- this.update([{ id: records[0].id, name: records[0].name }]);
+ if (records[0].state === '空闲') {
+ // const currentModel = this.env.models['mrp.workorder'];
+ console.log('currentModel',this)
+ console.log('this.record.data',this.record.data)
+ // const recordID = this.controllerParams.recordID;
+ // console.log('当前页面记录 ID:', recordID);
+ // console.log('this.record',this.record.id)
+ // console.log('this.record',this.controllerParams.recordID)
+ // const workorder = await this.orm.call('mrp.workorder', 'read', [this.record.data.id, ['id']]);
+ console.log('this.record.data.id', this.record.data.id)
+ const workorder = await this.orm.call('mrp.workorder', 'read', [this.record.data.id]);
+ console.log('workorder', workorder[0])
+ const updatedRecord = await this.orm.call("sf.tray", "write", [
+ [records[0].id],
+ {
+ // state: "占用",
+ workorder_id: workorder[0].id,
+ production_id: workorder[0].product_id[0],
+ // workorder_id: workorder.id,
+ }]);
+ console.log(workorder[0].routing_type);
+ console.log(workorder[0].production_id);
+ // const productionIDS = await this.orm.call('mrp.production', 'search', [[['id', '=', workorder[0].production_id[0]]]]);
+ const productionIDS = await this.orm.call('mrp.workorder', 'search', [[["production_id", "=", workorder[0].production_id[0]]]]);
+ console.log('prooooooo', productionIDS);
+ console.log('values', records[0].values[0]);
+ productionIDS.forEach(async (data) => {
+ // 处理每一个数据
+ console.log(data);
+ const updatetrayRecord = await this.orm.call("mrp.workorder", "write", [
+ [data],
+ {
+ tray_id: records[0].values[0].id,
+ // tray_id: false,
+ }]);
+ console.log(updatetrayRecord)
+ });
+ // this.trigger_up('reload')
+ // this.props.update(records[0].code, records[0].values);
+ this.props.update(records[0].code, records[0].tray_id);
+ // this.trigger_up('button_clicked', {
+ // attrs: {
+ // name: 'save',
+ // },
+ // });
+ // this.do_action({
+ // 'type': 'ir.actions.act_window',
+ // 'res_model': 'mrp.workorder',
+ // 'view_mode': 'form',
+ // 'view_type': 'form',
+ // 'res_id': workorder[0].id,
+ // 'target': 'current',
+ // })
+ } else {
+ if (records[0].state === '占用') {
+ console.log('此托盘已占用,请检查')
+ alert('此托盘已占用,请检查')
+ } else {
+ console.log('此托盘已损坏,请登记')
+ }
+ }
+
} else {
const searchInput = this.autocompleteContainerRef.el.querySelector("input");
searchInput.value = barcode;
@@ -64,19 +230,27 @@ export class CodeField extends Component {
}
CodeField.template = xml`
+
`;
// CodeField.template = 'sf_machine_connect.CodeField';
CodeField.props = standardFieldProps;
// Add the field to the correct category
-registry.category("fields").add("code", CodeField);
\ No newline at end of file
+registry.category("fields").add("code", CodeField);
+
+// style="position: relative; left: 200px;"
\ No newline at end of file
From e05db5f583c2834ea67faf06c9960b8648c5cccf Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Fri, 21 Apr 2023 18:02:25 +0800
Subject: [PATCH 8/9] =?UTF-8?q?=E5=A2=9E=E5=8A=A0jd=5Feclp=E6=A8=A1?=
=?UTF-8?q?=E5=9D=97=E5=BC=82=E5=B8=B8=E6=8D=95=E8=8E=B7=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_bf_connect/models/jd_eclp.py | 50 ++++++++++++++++-----------------
1 file changed, 25 insertions(+), 25 deletions(-)
diff --git a/sf_bf_connect/models/jd_eclp.py b/sf_bf_connect/models/jd_eclp.py
index 7eb1af20..5497482e 100644
--- a/sf_bf_connect/models/jd_eclp.py
+++ b/sf_bf_connect/models/jd_eclp.py
@@ -52,31 +52,31 @@ class JdEclp(models.Model):
sale_order_id = self.env['sale.order'].search([('name', '=', self.origin)])
# stock_picking_type_id = self.enc['stock.picking.type'].search([('picking_type_id', '=', '')])
# if sale_order_id.address_of_delivery != False:
-
-
-
- if 'OUT' in self.name:
- raw_addres = sale_order_id.address_of_delivery.split('这是一个标志位,用来不分隔字符串')
- # _logger.info('=================dddd====', sale_order_id.address_of_delivery)
- # _logger.info('=================dddd====', type(sale_order_id.address_of_delivery))
- # _logger.info('========================================', raw_addres)
- # _logger.info('=================dddd====', self.display_name)
- # _logger.info('=================dddd====', type(self.display_name))
- # # _logger.info(self.receiverName, self.receiverMobile)
- # _logger.info(1111111111111111111111111111111111111111111111)
- self.receiverName = sale_order_id.person_of_delivery
- self.receiverMobile = sale_order_id.telephone_of_delivery
- self.receiverProvinceName = cpca.transform(raw_addres).values.tolist()[0][0]
- self.receiverCityName = cpca.transform(raw_addres).values.tolist()[0][1]
- self.receiverCountyName = cpca.transform(raw_addres).values.tolist()[0][2]
- self.receiverTownName = cpca.transform(raw_addres).values.tolist()[0][3]
- else:
- self.receiverName = self.receiverName
- self.receiverMobile = self.receiverMobile
- self.receiverProvinceName = self.receiverProvinceName
- self.receiverCityName = self.receiverCityName
- self.receiverCountyName = self.receiverCountyName
- self.receiverTownName = self.receiverTownName
+ try:
+ if 'OUT' in self.name:
+ raw_addres = sale_order_id.address_of_delivery.split('这是一个标志位,用来不分隔字符串')
+ # _logger.info('=================dddd====', sale_order_id.address_of_delivery)
+ # _logger.info('========================================', raw_addres)
+ # _logger.info('=================dddd====', self.display_name)
+ # _logger.info('=================dddd====', type(self.display_name))
+ # # _logger.info(self.receiverName, self.receiverMobile)
+ # _logger.info(1111111111111111111111111111111111111111111111)
+ self.receiverName = sale_order_id.person_of_delivery
+ self.receiverMobile = sale_order_id.telephone_of_delivery
+ self.receiverProvinceName = cpca.transform(raw_addres).values.tolist()[0][0]
+ self.receiverCityName = cpca.transform(raw_addres).values.tolist()[0][1]
+ self.receiverCountyName = cpca.transform(raw_addres).values.tolist()[0][2]
+ self.receiverTownName = cpca.transform(raw_addres).values.tolist()[0][3]
+ else:
+ self.receiverName = self.receiverName
+ self.receiverMobile = self.receiverMobile
+ self.receiverProvinceName = self.receiverProvinceName
+ self.receiverCityName = self.receiverCityName
+ self.receiverCountyName = self.receiverCountyName
+ self.receiverTownName = self.receiverTownName
+ except Exception as e:
+ print(f"Error address is none: {e}")
+ pass
From 54b534d79257e55f61334bce6caf16e723aabbe2 Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Mon, 24 Apr 2023 14:27:33 +0800
Subject: [PATCH 9/9] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_machine_connect/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sf_machine_connect/__init__.py b/sf_machine_connect/__init__.py
index c536983e..9b429614 100644
--- a/sf_machine_connect/__init__.py
+++ b/sf_machine_connect/__init__.py
@@ -1,2 +1,2 @@
from . import models
-from . import wizard
\ No newline at end of file
+from . import wizard