From 8a0c968b10906e75e7dc8c500c9597c8c3bc1f3b Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Fri, 19 Jul 2024 17:25:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=94=E5=B7=A5bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_production.py | 62 +++++++------- sf_manufacturing/models/mrp_workorder.py | 40 +++++---- .../views/mrp_production_addional_change.xml | 2 +- sf_manufacturing/views/mrp_workorder_view.xml | 4 +- sf_manufacturing/wizard/rework_wizard.py | 84 +++++++++++++++++-- sf_sale/models/sale_order.py | 2 +- 6 files changed, 134 insertions(+), 60 deletions(-) diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 0f4cec78..fa64b71f 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -53,7 +53,6 @@ class MrpProduction(models.Model): check_status = fields.Boolean(string='启用状态', default=False, readonly=True) active = fields.Boolean(string='已归档', default=True) programming_no = fields.Char('编程单号') - reprogramming_num = fields.Integer('重新编程次数', default=0) work_state = fields.Char('业务状态') programming_state = fields.Selection( [('编程中', '编程中'), ('已编程', '已编程'), ('已编程未下发', '已编程未下发'), ('已下发', '已下发')], @@ -131,13 +130,15 @@ class MrpProduction(models.Model): if all(wo_state not in ('progress', 'done', 'rework') for wo_state in production.workorder_ids.mapped('state')): production.state = 'pending_cam' + if production.is_rework is True: + production.state = 'rework' # if production.state == 'pending_cam': # if all(wo_state in 'done' for wo_state in production.workorder_ids.mapped('state')): # production.state = 'done' if any( ( wo.test_results == '返工' and wo.state == 'done' and production.programming_state in [ - '已编程', '已下发']) or ( + '已编程']) or ( wo.state == 'rework' and production.programming_state == '编程中') or ( wo.is_rework is True and wo.state == 'done' and production.programming_state in ['编程中', '已编程']) @@ -179,11 +180,12 @@ class MrpProduction(models.Model): try: if not self: reproduction = self.env['mrp.production'].search( - [('state', '=', 'rework'), ('programming_state', '=', '编程中')]) + [('state', '=', 'rework'), ('programming_state', '=', '编程中'), ('is_rework', '=', True)]) else: reproduction = self if reproduction: - programming_no = [item.programming_no for item in reproduction] + programming_no_set = set([str(item.programming_no) for item in reproduction]) + programming_no = list(programming_no_set) programming_no_str = ','.join(programming_no) res = {'programming_no': programming_no_str} logging.info('res=%s:' % res) @@ -199,7 +201,8 @@ class MrpProduction(models.Model): for item in result['programming_list']: if not self: production = self.env['mrp.production'].search( - [('state', '=', 'rework'), ('programming_no', '=', item['programming_no'])]) + [('state', '=', 'rework'), + ('programming_no', '=', item['programming_no'], ('is_rework', '=', True))]) if production: production.write({'programming_state': '已编程未下发' if item[ 'programming_state'] == '已编程' else '编程中'}) @@ -746,17 +749,10 @@ class MrpProduction(models.Model): # 返工 def button_rework(self): cloud_programming = None - is_reprogramming = False - if self.programming_state == '已编程' and self.reprogramming_num >= 0: + if self.programming_state in ['已编程']: cloud_programming = self._cron_get_programming_state() - if self.reprogramming_num == 0: - self.reprogramming_num = cloud_programming['reprogramming_num'] - logging.info('cloud_programming_state:%s' % cloud_programming['programming_state']) + logging.info('cloud_programming_state:%s' % cloud_programming['programming_state']) logging.info('programming_state:%s' % self.programming_state) - if cloud_programming is None: - if self.reprogramming_num > 1: - is_reprogramming = False - return { 'name': _('返工'), 'type': 'ir.actions.act_window', @@ -765,9 +761,8 @@ class MrpProduction(models.Model): 'target': 'new', 'context': { 'default_production_id': self.id, - 'default_reprogramming_num': self.reprogramming_num, - 'default_programming_state': self.programming_state if cloud_programming is None else - cloud_programming['programming_state'], + '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 [ '编程中']) @@ -805,7 +800,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': '已编程'}) + production.write({'state': 'progress', 'programming_state': '已编程', 'is_rework': False}) # 从cloud获取重新编程过的最新程序 def get_new_program(self, processing_panel): @@ -819,31 +814,32 @@ 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'])]) + [('programming_no', '=', self.programming_no), ('state', 'not in', ('cancel', 'done'))]) if productions: panel_workorder = productions.workorder_ids.filtered( lambda - ac: ac.processing_panel == processing_panel and ac.routing_type == 'CNC加工' and ac.state != 'rework') + ac: ac.processing_panel == processing_panel and ac.routing_type == 'CNC加工' and ac.state not in ( + 'rework', 'done')) if panel_workorder: if panel_workorder.cnc_ids: panel_workorder.cmm_ids.sudo().unlink() 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 599b729c..b756086c 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -738,7 +738,10 @@ class ResMrpWorkOrder(models.Model): if re_work: if workorder.routing_type == '装夹预调' and workorder.state not in ['done', 'rework', 'cancel'] and workorder.is_rework is False: - workorder.state = 'waiting' + if workorder.production_id.programming_state == '已编程': + workorder.state = 'ready' + else: + 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), @@ -750,7 +753,8 @@ 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', '=', 'done'), + ('test_results', '=', '返工')]) if cnc_workorder: workorder.state = 'waiting' elif workorder.production_id.state == 'progress': @@ -759,14 +763,13 @@ class ResMrpWorkOrder(models.Model): logging.info('状态:%s' % workorder.state) logging.info('is_rework:%s' % workorder.is_rework) logging.info('面:%s' % workorder.processing_panel) - logging.info('reprogramming_num:%s' % workorder.production_id.reprogramming_num) logging.info('编程状态:%s' % workorder.production_id.programming_state) logging.info('制造状态:%s' % workorder.production_id.state) if workorder.routing_type == '装夹预调' and workorder.production_id.programming_state == '已编程' and \ workorder.is_rework is False and workorder.state not in [ 'done', 'rework', 'cancel']: - if re_work: + if re_work and workorder.production_id.is_rework is False: workorder.state = 'ready' # else: # if workorder.state not in ['cancel', 'rework']: @@ -916,16 +919,15 @@ class ResMrpWorkOrder(models.Model): record.process_state = '待解除装夹' # record.write({'process_state': '待加工'}) record.production_id.process_state = '待解除装夹' - if record.test_results in ['返工', '报废']: - record.production_id.write({'detection_result_ids': [(0, 0, { - 'rework_reason': record.reason, - 'detailed_reason': record.detailed_reason, - 'processing_panel': record.processing_panel, - 'routing_type': record.routing_type, - 'handle_result': '待处理' if record.test_results == '返工' or record.is_rework is True else '', - 'test_results': record.test_results, - 'test_report': record.detection_report})], - 'is_scrap': True if record.test_results == '报废' else False}) + record.production_id.write({'detection_result_ids': [(0, 0, { + 'rework_reason': record.reason, + 'detailed_reason': record.detailed_reason, + 'processing_panel': record.processing_panel, + 'routing_type': record.routing_type, + 'handle_result': '待处理' if record.test_results == '返工' or record.is_rework is True else '', + 'test_results': record.test_results, + 'test_report': record.detection_report})], + 'is_scrap': True if record.test_results == '报废' else False}) if record.routing_type == '解除装夹': ''' 记录结束时间 @@ -980,10 +982,12 @@ class ResMrpWorkOrder(models.Model): # record.production_id.workorder_ids.write({'rfid_code': False, 'rfid_code_old': record.rfid_code}) # if record.is_remanufacture is True: # record.recreateManufacturingOrWorkerOrder() - is_production_id = True - for workorder in record.production_id.workorder_ids: - if workorder.state != 'done': - is_production_id = False + is_production_id = False + rework_workorder = record.production_id.workorder_ids.filtered(lambda p: p.state == 'rework') + done_workorder = record.production_id.workorder_ids.filtered(lambda p1: p1.state == 'done') + if (len(rework_workorder) + len(done_workorder) == len(record.production_id.workorder_ids)) or ( + len(done_workorder) == len(record.production_id.workorder_ids)): + is_production_id = True if record.routing_type in ['解除装夹'] or ( record.is_rework is True and record.routing_type in ['装夹预调']) or ( record.test_results in ['返工', '报废'] and record.routing_type in ['CNC加工']): diff --git a/sf_manufacturing/views/mrp_production_addional_change.xml b/sf_manufacturing/views/mrp_production_addional_change.xml index 28da8c14..8b539de2 100644 --- a/sf_manufacturing/views/mrp_production_addional_change.xml +++ b/sf_manufacturing/views/mrp_production_addional_change.xml @@ -124,7 +124,7 @@ confirm="是否确认更新程序" attrs="{'invisible': ['|',('state', '!=', 'rework'),('programming_state', '!=', '已编程未下发')]}"/>