From fe88a416a7d42e0a9d6b4fdbc129f39339a8677d Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Tue, 28 May 2024 17:57:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=B6=E9=80=A0=E8=AE=A2=E5=8D=95=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E4=B8=80=E5=BC=A0=E7=BC=96=E7=A8=8B=E5=8D=95=E4=B8=8B?= =?UTF-8?q?=E5=8F=91=E6=97=B6=EF=BC=8C=E5=B7=A5=E4=BB=B6=E9=85=8D=E9=80=81?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E7=9A=84=E6=9C=AA=E4=B8=8B=E5=8F=91nc?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E4=B8=BA=E6=9C=AA=E4=B8=8B=E5=8F=91=E5=8F=8A?= =?UTF-8?q?cnc=E7=A8=8B=E5=BA=8F=E6=B2=A1=E6=9C=89=E5=AF=B9=E5=BA=94ftp?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_production.py | 10 ++++++-- sf_manufacturing/models/mrp_workorder.py | 31 +++++++++++++++-------- sf_manufacturing/models/stock.py | 4 +-- sf_mrs_connect/controllers/controllers.py | 14 ++++++---- sf_mrs_connect/models/ftp_operate.py | 2 ++ 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 69f06d03..4ed3368f 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -335,10 +335,10 @@ class MrpProduction(models.Model): production_programming = self.search( [('product_id.id', '=', production.product_id.id), ('origin', '=', production.origin)], limit=1, order='id asc') - if not production_programming.programming_no: + if not production_programming.programming_no or (is_fetchcnc is True and scrap_production): # 制造订单报废/返工也需重新编程 if (is_fetchcnc is True and scrap_production) or ( - is_fetchcnc is False and not scrap_production): + is_fetchcnc is False and scrap_production): production.fetchCNC(', '.join(product_id_to_production_names[production.product_id.id]), scrap_production) else: @@ -408,6 +408,12 @@ class MrpProduction(models.Model): workorders_values.append( self.env['mrp.workorder'].json_workorder_str('', production, route)) production.workorder_ids = workorders_values + if is_fetchcnc is False and scrap_production: + production.write({'programming_no': scrap_production.programming_no, + 'programming_state': '已编程'}) + production.workorder_ids.filtered(lambda t: t.routing_type == 'CNC加工').write({ + 'cnc_ids': scrap_production.workorder_ids.filtered( + lambda t1: t1.routing_type == 'CNC加工').cnc_ids}) for workorder in production.workorder_ids: workorder.duration_expected = workorder._get_duration_expected() diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index f5452aaf..ea76896a 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -766,6 +766,7 @@ class ResMrpWorkOrder(models.Model): sale_order = self.env['sale.order'].sudo().search([('name', '=', productions.origin)]) if sale_order: + sale_order.mrp_production_ids |= productions # sale_order.write({'schedule_status': 'to schedule'}) self.env['sf.production.plan'].sudo().with_company(self.production_id.company_id).create({ 'name': productions.name, @@ -995,7 +996,7 @@ class ResMrpWorkOrder(models.Model): 'date_planned_finished': tem_date_planned_finished # 保持原值 }) if record.routing_type == 'CNC加工' and record.test_results in ['返工', '报废']: - record.production_id.write({'state': 'cancel'}) + record.production_id.action_cancel() record.production_id.workorder_ids.write({'rfid_code': False, 'rfid_code_old': record.rfid_code}) if record.is_remanufacture is True: record.recreateManufacturingOrWorkerOrder() @@ -1130,6 +1131,8 @@ class CNCprocessing(models.Model): 'cutting_tool_extension_length': obj['cutting_tool_extension_length'], 'cutting_tool_handle_type': obj['cutting_tool_handle_type'], 'estimated_processing_time': obj['estimated_processing_time'], + 'program_path': obj['program_path'], + 'cnc_id': obj['cnc_id'].id, 'remark': obj['remark'] }) return cnc_processing_str @@ -1137,19 +1140,27 @@ class CNCprocessing(models.Model): # 根据程序名和加工面匹配到ftp里对应的Nc程序名,可优化为根据cnc_processing.program_path进行匹配 def get_cnc_processing_file(self, serverdir, cnc_processing, program_path): logging.info('serverdir:%s' % serverdir) + logging.info('cnc_processing:%s' % cnc_processing) for root, dirs, files in os.walk(serverdir): for f in files: + logging.info('splitext(f):%s' % os.path.splitext(f)[1]) if os.path.splitext(f)[1] == ".pdf": full_path = os.path.join(serverdir, root, f) - if full_path is not False: - if not cnc_processing.workorder_id.cnc_worksheet: - cnc_processing.workorder_id.cnc_worksheet = base64.b64encode( - open(full_path, 'rb').read()) - else: - if f in program_path: - # if cnc_processing.program_name == f.split('.')[0]: - cnc_file_path = os.path.join(serverdir, root, f) - self.write_file(cnc_file_path, cnc_processing) + logging.info('full_path:%s' % full_path) + logging.info('routing_type:%s' % cnc_processing.workorder_id.routing_type) + logging.info('cnc_worksheet:%s' % cnc_processing.workorder_id.cnc_worksheet) + # with open(full_path, 'rb') as pdf_file: + # file_content = pdf_file.read() + # cnc_processing.workorder_id.cnc_worksheet = base64.b64encode(file_content) + if not cnc_processing.workorder_id.cnc_worksheet: + logging.info('full_path111555:%s' % full_path) + cnc_processing.workorder_id.cnc_worksheet = base64.b64encode( + open(full_path, 'rb').read()) + else: + if f in program_path: + # if cnc_processing.program_name == f.split('.')[0]: + cnc_file_path = os.path.join(serverdir, root, f) + self.write_file(cnc_file_path, cnc_processing) # 创建附件(nc文件) def attachment_create(self, name, data): diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index cc4999b7..806a13de 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -631,8 +631,8 @@ class ReStockMove(models.Model): 'reserved_uom_qty': 1.0, 'lot_id': purchase.picking_ids.move_line_ids.lot_id.id, 'company_id': self.company_id.id, - 'workorder_id': '' if not sorted_workorders else sorted_workorders.id, - 'production_id': '' if not sorted_workorders else sorted_workorders.production_id.id, + # 'workorder_id': '' if not sorted_workorders else sorted_workorders.id, + # 'production_id': '' if not sorted_workorders else sorted_workorders.production_id.id, 'state': 'assigned', } diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py index 98c2d59e..08d6d9b4 100644 --- a/sf_mrs_connect/controllers/controllers.py +++ b/sf_mrs_connect/controllers/controllers.py @@ -63,12 +63,16 @@ class Sf_Mrs_Connect(http.Controller): logging.info('cnc_processing111:%s' % cnc_processing) if cnc_processing: cnc_processing_arr.append(cnc_processing._json_cnc_processing(cnc_processing)) - if cnc_program and cnc_processing_arr: + if (cnc_program and cnc_processing_arr) or (not cnc_program and cnc_processing_arr): logging.info('cnc_processing_arr:%s' % cnc_processing_arr) - cnc_program.write({'programming_state': '已编程', 'work_state': '已编程'}) - cnc_program.workorder_ids.filtered(lambda b: b.routing_type == 'CNC加工').write( - {'cnc_ids': cnc_processing_arr, 'cnc_worksheet': cnc_production.workorder_ids.filtered( - lambda b: b.routing_type == 'CNC加工').cnc_worksheet}) + if cnc_program and cnc_processing_arr: + cnc_program.write({'programming_state': '已编程', 'work_state': '已编程'}) + cnc_program.workorder_ids.filtered(lambda b: b.routing_type == 'CNC加工').write( + {'cnc_ids': cnc_processing_arr, 'cnc_worksheet': cnc_production.workorder_ids.filtered( + lambda b: b.routing_type == 'CNC加工').cnc_worksheet}) + cnc_program |= cnc_production + if not cnc_program and cnc_processing_arr: + cnc_program = cnc_production cnc_program_ids = [item.id for item in cnc_program] workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search( [('production_id', 'in', cnc_program_ids)]) diff --git a/sf_mrs_connect/models/ftp_operate.py b/sf_mrs_connect/models/ftp_operate.py index 8b547bb3..4cd5e3ba 100644 --- a/sf_mrs_connect/models/ftp_operate.py +++ b/sf_mrs_connect/models/ftp_operate.py @@ -46,6 +46,8 @@ class FtpController(): os.makedirs(serverdir) try: logging.info("进入FTP目录 ") + self.ftp.pwd() + logging.info('当前目录:%s' % self.ftp.pwd()) logging.info('目录:%s' % target_dir) target_dir1 = target_dir.split('/') logging.info('目录1:%s' % target_dir1[1])