From 83396f543413e3effcb884c30af73f681710f732 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Mon, 22 Jul 2024 17:32:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=94=E5=B7=A5(CNC?= =?UTF-8?q?=E5=8A=A0=E5=B7=A5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_production.py | 31 +++++++------ sf_manufacturing/models/mrp_workorder.py | 50 ++++++++++++--------- sf_manufacturing/models/product_template.py | 4 +- sf_sale/models/quick_easy_order.py | 4 +- sf_sale/models/quick_easy_order_old.py | 4 +- 5 files changed, 53 insertions(+), 40 deletions(-) diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index b7c8fe91..ae523bd9 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -204,7 +204,7 @@ class MrpProduction(models.Model): if rp.programming_no == item['programming_no']: rp.write({'programming_state': '已编程未下发' if item[ 'programming_state'] == '已编程' else '编程中'}) - logging.info('rp:' % rp.name) + logging.info('rp:%s' % rp.name) else: return item @@ -792,6 +792,8 @@ class MrpProduction(models.Model): program_to_production_names[programming_no] = [production.name for production in program_production] for production in self: if production.programming_no in program_to_production_names: + productions_not_delivered = self.env['mrp.production'].search( + [('programming_no', '=', production.programming_no), ('programming_state', '=', '已编程未下发')]) rework_workorder = production.workorder_ids.filtered(lambda m: m.state == 'rework') if rework_workorder: for rework_item in rework_workorder: @@ -801,6 +803,7 @@ class MrpProduction(models.Model): if not pending_workorder.cnc_ids: production.get_new_program(rework_item.processing_panel) production.write({'state': 'progress', 'programming_state': '已编程', 'is_rework': False}) + productions_not_delivered.write({'programming_state': '已编程', 'is_rework': False}) # 从cloud获取重新编程过的最新程序 def get_new_program(self, processing_panel): @@ -814,17 +817,17 @@ class MrpProduction(models.Model): r = r.json() result = json.loads(r['result']) if result['status'] == 1: - program_path_tmp_panel = os.path.join('/tmp', result['folder_name'], 'return', processing_panel) - if os.path.exists(program_path_tmp_panel): - files_r = os.listdir(program_path_tmp_panel) - if files_r: - for file_name in files_r: - file_path = os.path.join(program_path_tmp_panel, file_name) - os.remove(file_path) - download_state = self.env['sf.cnc.processing'].download_file_tmp(result['folder_name'], - processing_panel) - if download_state is False: - raise UserError('编程单号为%s的CNC程序文件从FTP拉取失败' % (self.programming_no)) + # program_path_tmp_panel = os.path.join('/tmp', result['folder_name'], 'return', processing_panel) + # if os.path.exists(program_path_tmp_panel): + # files_r = os.listdir(program_path_tmp_panel) + # if files_r: + # for file_name in files_r: + # file_path = os.path.join(program_path_tmp_panel, file_name) + # os.remove(file_path) + # download_state = self.env['sf.cnc.processing'].download_file_tmp(result['folder_name'], + # processing_panel) + # if download_state is False: + # raise UserError('编程单号为%s的CNC程序文件从FTP拉取失败' % (self.programming_no)) productions = self.env['mrp.production'].search( [('programming_no', '=', self.programming_no), ('state', 'not in', ('cancel', 'done'))]) if productions: @@ -838,8 +841,8 @@ class MrpProduction(models.Model): panel_workorder.cnc_ids.sudo().unlink() self.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan( productions) - # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', - # processing_panel) + program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', + processing_panel) logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel) files_panel = os.listdir(program_path_tmp_panel) if files_panel: diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index a4b0527c..6ffdb0cb 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -726,6 +726,11 @@ class ResMrpWorkOrder(models.Model): re_work = self.env['mrp.workorder'].search([('production_id', '=', workorder.production_id.id), ('processing_panel', '=', workorder.processing_panel), ('is_rework', '=', True), ('state', 'in', ['done', 'rework'])]) + cnc_workorder = self.env['mrp.workorder'].search( + [('production_id', '=', workorder.production_id.id), + ('processing_panel', '=', workorder.processing_panel), + ('routing_type', '=', 'CNC加工'), ('state', '=', 'done'), + ('test_results', '=', '返工')]) if workorder.state not in ['cancel', 'progress', 'rework']: if workorder.production_id.state == 'rework': logging.info('len(re_work):%s' % len(re_work)) @@ -736,29 +741,34 @@ class ResMrpWorkOrder(models.Model): logging.info('面:%s' % workorder.processing_panel) logging.info('编程状态:%s' % workorder.production_id.programming_state) logging.info('制造状态:%s' % workorder.production_id.state) - if re_work: - if workorder.routing_type == '装夹预调' and workorder.state not in ['done', 'rework', - 'cancel'] and workorder.is_rework is False: - if workorder.production_id.programming_state == '已编程': - workorder.state = 'ready' + if workorder.routing_type == '装夹预调' and workorder.state not in ['done', 'rework', + 'cancel']: + # # 有返工工单 + # if re_work: + # 新工单 + if workorder.is_rework is False: + if workorder.production_id.programming_state == '已编程' and workorder.production_id.is_rework is False: + if re_work: + workorder.state = 'ready' else: if workorder.production_id.is_rework is True: - workorder.state = 'waiting' - if workorder.routing_type == 'CNC加工' and workorder.state not in ['done', 'rework', 'cancel']: - pre_workorder = self.env['mrp.workorder'].search( - [('production_id', '=', workorder.production_id.id), - ('processing_panel', '=', workorder.processing_panel), - ('routing_type', '=', '装夹预调'), ('state', '=', 'done')]) - if pre_workorder: - workorder.state = 'waiting' - if workorder.routing_type == '解除装夹' and workorder.state not in ['done', 'rework', 'cancel']: - cnc_workorder = self.env['mrp.workorder'].search( - [('production_id', '=', workorder.production_id.id), - ('processing_panel', '=', workorder.processing_panel), - ('routing_type', '=', 'CNC加工'), ('state', '=', 'done'), - ('test_results', '=', '返工')]) - if cnc_workorder: + if re_work or cnc_workorder: + workorder.state = 'waiting' + + elif workorder.routing_type == 'CNC加工' and workorder.state not in ['done', 'rework', 'cancel']: + pre_workorder = self.env['mrp.workorder'].search( + [('production_id', '=', workorder.production_id.id), + ('processing_panel', '=', workorder.processing_panel), + ('routing_type', '=', '装夹预调'), ('state', '=', 'done')]) + if pre_workorder: + if re_work: workorder.state = 'waiting' + elif workorder.routing_type == '解除装夹' and workorder.state not in ['done', 'rework', 'cancel']: + if cnc_workorder: + workorder.state = 'waiting' + # else: + # if workorder.production_id.is_rework is True: + # workorder.state = 'waiting' elif workorder.production_id.state == 'progress': logging.info('len(re_work):%s' % len(re_work)) logging.info('工序:%s' % workorder.routing_type) diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py index 4d05de81..f292d694 100644 --- a/sf_manufacturing/models/product_template.py +++ b/sf_manufacturing/models/product_template.py @@ -7,8 +7,8 @@ import os from odoo import models, fields, api, _ from odoo.exceptions import ValidationError from odoo.modules import get_resource_path -from OCC.Extend.DataExchange import read_step_file -from OCC.Extend.DataExchange import write_stl_file +# from OCC.Extend.DataExchange import read_step_file +# from OCC.Extend.DataExchange import write_stl_file class ResProductMo(models.Model): diff --git a/sf_sale/models/quick_easy_order.py b/sf_sale/models/quick_easy_order.py index e3bf3002..11acc06f 100644 --- a/sf_sale/models/quick_easy_order.py +++ b/sf_sale/models/quick_easy_order.py @@ -8,8 +8,8 @@ from datetime import datetime import requests from odoo import http from odoo.http import request -from OCC.Extend.DataExchange import read_step_file -from OCC.Extend.DataExchange import write_stl_file +# from OCC.Extend.DataExchange import read_step_file +# from OCC.Extend.DataExchange import write_stl_file from odoo import models, fields, api from odoo.modules import get_resource_path from odoo.exceptions import ValidationError, UserError diff --git a/sf_sale/models/quick_easy_order_old.py b/sf_sale/models/quick_easy_order_old.py index 3ae65db3..92f6cda2 100644 --- a/sf_sale/models/quick_easy_order_old.py +++ b/sf_sale/models/quick_easy_order_old.py @@ -6,8 +6,8 @@ import os from datetime import datetime from stl import mesh # from OCC.Core.GProp import GProp_GProps -from OCC.Extend.DataExchange import read_step_file -from OCC.Extend.DataExchange import write_stl_file +# from OCC.Extend.DataExchange import read_step_file +# from OCC.Extend.DataExchange import write_stl_file from odoo.addons.sf_base.commons.common import Common from odoo import models, fields, api from odoo.modules import get_resource_path From ded17898130781794608426a7289be9f896a3076 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Tue, 23 Jul 2024 10:33:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=94=E5=B7=A5(CNC?= =?UTF-8?q?=E5=8A=A0=E5=B7=A5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/controllers/controllers.py | 2 +- sf_manufacturing/models/mrp_production.py | 34 ++++++++----------- sf_manufacturing/models/mrp_workorder.py | 4 ++- sf_manufacturing/models/product_template.py | 4 +-- .../wizard/rework_wizard_views.xml | 6 ++-- sf_sale/models/quick_easy_order.py | 4 +-- sf_sale/models/quick_easy_order_old.py | 4 +-- 7 files changed, 28 insertions(+), 30 deletions(-) diff --git a/sf_manufacturing/controllers/controllers.py b/sf_manufacturing/controllers/controllers.py index 6624e709..33939c72 100644 --- a/sf_manufacturing/controllers/controllers.py +++ b/sf_manufacturing/controllers/controllers.py @@ -242,7 +242,7 @@ class Manufacturing_Connect(http.Controller): logging.info('button_Work_End error:%s' % e) return json.JSONEncoder().encode(res) - @http.route('/AutoDeviceApi/PartQualityInspect', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False, + @http.route('/AutoDeviceApi/PartQualityInspect', type='json', auth='none', methods=['GET', 'POST'], csrf=False, cors="*") def PartQualityInspect(self, **kw): """ diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index ae523bd9..88ca4c2c 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -763,11 +763,7 @@ class MrpProduction(models.Model): 'default_production_id': self.id, 'default_reprogramming_num': cloud_programming['reprogramming_num'], 'default_programming_state': cloud_programming['programming_state'], - 'default_is_reprogramming': False if (cloud_programming['programming_state'] in ['编程中', - '待编程'] and self.programming_state in [ - '编程中', '已编程']) - or (cloud_programming['programming_state'] in [ - '已编程'] and self.programming_state in ['已编程未下发']) else True + 'default_is_reprogramming': False if cloud_programming['programming_state'] not in ['已下发'] else True } } @@ -802,7 +798,7 @@ class MrpProduction(models.Model): 'pending'] and m1.processing_panel == rework_item.processing_panel and m1.routing_type == 'CNC加工') if not pending_workorder.cnc_ids: production.get_new_program(rework_item.processing_panel) - production.write({'state': 'progress', 'programming_state': '已编程', 'is_rework': False}) + # production.write({'state': 'progress', 'programming_state': '已编程', 'is_rework': False}) productions_not_delivered.write({'programming_state': '已编程', 'is_rework': False}) # 从cloud获取重新编程过的最新程序 @@ -817,17 +813,17 @@ class MrpProduction(models.Model): r = r.json() result = json.loads(r['result']) if result['status'] == 1: - # program_path_tmp_panel = os.path.join('/tmp', result['folder_name'], 'return', processing_panel) - # if os.path.exists(program_path_tmp_panel): - # files_r = os.listdir(program_path_tmp_panel) - # if files_r: - # for file_name in files_r: - # file_path = os.path.join(program_path_tmp_panel, file_name) - # os.remove(file_path) - # download_state = self.env['sf.cnc.processing'].download_file_tmp(result['folder_name'], - # processing_panel) - # if download_state is False: - # raise UserError('编程单号为%s的CNC程序文件从FTP拉取失败' % (self.programming_no)) + program_path_tmp_panel = os.path.join('/tmp', result['folder_name'], 'return', processing_panel) + if os.path.exists(program_path_tmp_panel): + files_r = os.listdir(program_path_tmp_panel) + if files_r: + for file_name in files_r: + file_path = os.path.join(program_path_tmp_panel, file_name) + os.remove(file_path) + download_state = self.env['sf.cnc.processing'].download_file_tmp(result['folder_name'], + processing_panel) + if download_state is False: + raise UserError('编程单号为%s的CNC程序文件从FTP拉取失败' % (self.programming_no)) productions = self.env['mrp.production'].search( [('programming_no', '=', self.programming_no), ('state', 'not in', ('cancel', 'done'))]) if productions: @@ -841,8 +837,8 @@ class MrpProduction(models.Model): panel_workorder.cnc_ids.sudo().unlink() self.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan( productions) - program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', - processing_panel) + # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', + # processing_panel) logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel) files_panel = os.listdir(program_path_tmp_panel) if files_panel: diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 6ffdb0cb..e8458d29 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -729,11 +729,12 @@ class ResMrpWorkOrder(models.Model): cnc_workorder = self.env['mrp.workorder'].search( [('production_id', '=', workorder.production_id.id), ('processing_panel', '=', workorder.processing_panel), - ('routing_type', '=', 'CNC加工'), ('state', '=', 'done'), + ('routing_type', '=', 'CNC加工'), ('state', 'in', ['done', 'rework']), ('test_results', '=', '返工')]) if workorder.state not in ['cancel', 'progress', 'rework']: if workorder.production_id.state == 'rework': logging.info('len(re_work):%s' % len(re_work)) + logging.info('len(cnc_workorder):%s' % len(cnc_workorder)) logging.info('工序:%s' % workorder.routing_type) logging.info('状态:%s' % workorder.state) logging.info('is_rework:%s' % workorder.is_rework) @@ -771,6 +772,7 @@ class ResMrpWorkOrder(models.Model): # workorder.state = 'waiting' elif workorder.production_id.state == 'progress': logging.info('len(re_work):%s' % len(re_work)) + logging.info('len(cnc_workorder):%s' % len(cnc_workorder)) logging.info('工序:%s' % workorder.routing_type) logging.info('状态:%s' % workorder.state) logging.info('is_rework:%s' % workorder.is_rework) diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py index f292d694..4d05de81 100644 --- a/sf_manufacturing/models/product_template.py +++ b/sf_manufacturing/models/product_template.py @@ -7,8 +7,8 @@ import os from odoo import models, fields, api, _ from odoo.exceptions import ValidationError from odoo.modules import get_resource_path -# from OCC.Extend.DataExchange import read_step_file -# from OCC.Extend.DataExchange import write_stl_file +from OCC.Extend.DataExchange import read_step_file +from OCC.Extend.DataExchange import write_stl_file class ResProductMo(models.Model): diff --git a/sf_manufacturing/wizard/rework_wizard_views.xml b/sf_manufacturing/wizard/rework_wizard_views.xml index 524bb8ae..49274368 100644 --- a/sf_manufacturing/wizard/rework_wizard_views.xml +++ b/sf_manufacturing/wizard/rework_wizard_views.xml @@ -20,13 +20,13 @@ style='color:red;'/>次,且当前编程状态为 + decoration-danger="programming_state =='已编程'" readonly="1"/> + attrs='{"invisible": [("routing_type","in",["装夹预调","CNC加工"])],"readonly": [("is_reprogramming","=",False)]}'/>