From a2855f1f088102e9c8d9a36fe03a9d3db4a3b466 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Mon, 18 Nov 2024 11:40:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=98=E5=8E=9F=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_workorder.py | 18 ++--- sf_manufacturing/models/stock.py | 9 +-- sf_manufacturing/views/mrp_workorder_view.xml | 4 +- sf_mrs_connect/controllers/controllers.py | 81 +++++++++---------- 4 files changed, 51 insertions(+), 61 deletions(-) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 074ca01e..3443094f 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -1005,14 +1005,6 @@ class ResMrpWorkOrder(models.Model): def _compute_state(self): # super()._compute_state() for workorder in self: - logging.info(workorder.name) - logging.info(workorder.state) - logging.info(workorder.sequence) - logging.info(workorder.id) - # logging.info(workorder.blocked_by_workorder_ids) - # logging.info(workorder.blocked_by_workorder_ids.name) - # logging.info(workorder.blocked_by_workorder_ids.sequence) - logging.info('----------------------') if workorder.sequence != 1: previous_workorder = self.env['mrp.workorder'].search( [('production_id', '=', workorder.production_id.id), @@ -1308,9 +1300,9 @@ class ResMrpWorkOrder(models.Model): if record.routing_type == '装夹预调': if not record.rfid_code and record.is_rework is False: raise UserError("请扫RFID码进行绑定") - # if record.is_rework is False: - # if not record.material_center_point: - # raise UserError("坯料中心点为空,请检查") + if record.is_rework is False: + if not record.material_center_point: + raise UserError("坯料中心点为空,请检查") # if record.X_deviation_angle <= 0: # raise UserError("X偏差角度小于等于0,请检查!本次计算的X偏差角度为:%s" % record.X_deviation_angle) record.process_state = '待加工' @@ -1344,8 +1336,8 @@ class ResMrpWorkOrder(models.Model): if record.routing_type == '表面工艺': if record.picking_ids: picks = record.picking_ids.filtered(lambda p: p.state not in ('done')) - # if picks: - # raise UserError('请先完成该工单的工艺外协再进行操作') + if picks: + raise UserError('请先完成该工单的工艺外协再进行操作') tem_date_planned_finished = record.date_planned_finished tem_date_finished = record.date_finished logging.info('routing_type:%s' % record.routing_type) diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index cb4ac951..6c7a8b35 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -294,10 +294,10 @@ class StockRule(models.Model): # 为同一个product_id创建一个生产订单名称列表 product_id_to_production_names[product_id] = [production.name for production in all_production] for production_item in productions: - # production_programming = self.env['mrp.production'].search( - # [('product_id.id', '=', production_item.product_id.id), - # ('origin', '=', production_item.origin)], - # limit=1, order='id asc') + production_programming = self.env['mrp.production'].search( + [('product_id.id', '=', production_item.product_id.id), + ('origin', '=', production_item.origin)], + limit=1, order='id asc') if production_item.product_id.id in product_id_to_production_names: # 同一个产品多个制造订单对应一个编程单和模型库 # 只调用一次fetchCNC,并将所有生产订单的名称作为字符串传递 @@ -310,7 +310,6 @@ class StockRule(models.Model): 'programming_state': '编程中'}) if not technology_design_values: if production_item.product_id.categ_id.type == '成品': - production_item.product_id.model_processing_panel = 'ZM,FM' # 根据加工面板的面数及成品工序模板生成工序设计 i = 0 for k in (production_item.product_id.model_processing_panel.split(',')): diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index 5055b7fa..bbda259c 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -250,8 +250,8 @@ - + diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py index ae8597b9..5f5aee06 100644 --- a/sf_mrs_connect/controllers/controllers.py +++ b/sf_mrs_connect/controllers/controllers.py @@ -28,27 +28,27 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController): domain = [('programming_no', '=', ret['programming_no'])] if ret['manufacturing_type'] in ('scrap', 'invalid_tool_rework'): domain += [('state', 'not in', ['done', 'scrap', 'cancel'])] + else: + domain += [('state', '=', 'confirmed')] productions = request.env['mrp.production'].with_user( request.env.ref("base.user_admin")).search(domain) - production_technology_comfirm = request.env['mrp.production'].with_user( - request.env.ref("base.user_admin")).search([('programming_no', '=', ret['programming_no']),('state','=','confirmed')]) if productions: # 拉取所有加工面的程序文件 - # for r in ret['processing_panel'].split(','): - # program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r) - # if os.path.exists(program_path_tmp_r): - # files_r = os.listdir(program_path_tmp_r) - # if files_r: - # for file_name in files_r: - # file_path = os.path.join(program_path_tmp_r, file_name) - # os.remove(file_path) - # download_state = request.env['sf.cnc.processing'].with_user( - # request.env.ref("base.user_admin")).download_file_tmp( - # ret['folder_name'], r) - # if download_state is False: - # res['status'] = -2 - # res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no']) - # return json.JSONEncoder().encode(res) + for r in ret['processing_panel'].split(','): + program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r) + if os.path.exists(program_path_tmp_r): + files_r = os.listdir(program_path_tmp_r) + if files_r: + for file_name in files_r: + file_path = os.path.join(program_path_tmp_r, file_name) + os.remove(file_path) + download_state = request.env['sf.cnc.processing'].with_user( + request.env.ref("base.user_admin")).download_file_tmp( + ret['folder_name'], r) + if download_state is False: + res['status'] = -2 + res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no']) + return json.JSONEncoder().encode(res) for production in productions: for panel in ret['processing_panel'].split(','): # 查询状态为进行中且工序类型为CNC加工的工单 @@ -65,30 +65,29 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController): cnc_workorder_has.write( {'cnc_ids': cnc_workorder_has.cnc_ids.sudo()._json_cnc_processing(panel, ret), 'cmm_ids': cnc_workorder_has.cmm_ids.sudo()._json_cmm_program(panel, ret)}) - # for panel in ret['processing_panel'].split(','): - # # 查询状态为进行中且工序类型为CNC加工的工单 - # cnc_workorder = productions.workorder_ids.filtered( - # lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', 'rework' - # 'cancel'] and ac.processing_panel == panel) - # if cnc_workorder: - # # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', - # # panel) - # program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', panel) - # logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel) - # files_panel = os.listdir(program_path_tmp_panel) - # if files_panel: - # for file in files_panel: - # file_extension = os.path.splitext(file)[1] - # if file_extension.lower() == '.pdf': - # panel_file_path = os.path.join(program_path_tmp_panel, file) - # logging.info('panel_file_path:%s' % panel_file_path) - # cnc_workorder.write({'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())}) - # pre_workorder = productions.workorder_ids.filtered( - # lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', 'rework' - # 'cancel'] and ap.processing_panel == panel) - # if pre_workorder: - # pre_workorder.write( - # {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) + for panel in ret['processing_panel'].split(','): + # 查询状态为进行中且工序类型为CNC加工的工单 + cnc_workorder = productions.workorder_ids.filtered( + lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', 'rework' + 'cancel'] and ac.processing_panel == panel) + if cnc_workorder: + # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', + # panel) + program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', panel) + files_panel = os.listdir(program_path_tmp_panel) + if files_panel: + for file in files_panel: + file_extension = os.path.splitext(file)[1] + if file_extension.lower() == '.pdf': + panel_file_path = os.path.join(program_path_tmp_panel, file) + logging.info('panel_file_path:%s' % panel_file_path) + cnc_workorder.write({'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())}) + pre_workorder = productions.workorder_ids.filtered( + lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', 'rework' + 'cancel'] and ap.processing_panel == panel) + if pre_workorder: + pre_workorder.write( + {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) productions.write({'programming_state': '已编程', 'work_state': '已编程'}) logging.info('已更新制造订单编程状态:%s' % productions.ids) res.update({