diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 33795920..6837b03a 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -800,7 +800,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'] not in ['已下发'] else True + 'default_is_reprogramming': True if cloud_programming['programming_state'] in ['已下发'] else False } } diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 303a4966..800c412d 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -13,7 +13,7 @@ from dateutil.relativedelta import relativedelta # import subprocess from odoo import api, fields, models, SUPERUSER_ID, _ from odoo.addons.sf_base.commons.common import Common -from odoo.exceptions import UserError,ValidationError +from odoo.exceptions import UserError, ValidationError from odoo.addons.sf_mrs_connect.models.ftp_operate import FtpController @@ -801,6 +801,13 @@ class ResMrpWorkOrder(models.Model): 'cancel']: if re_work and workorder.production_id.is_rework is False: workorder.state = 'ready' + if workorder.routing_type == '表面工艺' and workorder.state not in ['done', 'progress']: + unclamp_workorder = self.env['mrp.workorder'].search( + [('production_id', '=', workorder.production_id.id), + ('sequence', '=', workorder.sequence - 1), + ('state', 'in', ['done'])]) + if unclamp_workorder: + workorder.state = 'ready' # else: # if workorder.state not in ['cancel', 'rework']: # workorder.state = 'rework' diff --git a/sf_manufacturing/wizard/rework_wizard.py b/sf_manufacturing/wizard/rework_wizard.py index e018b30a..c50e267d 100644 --- a/sf_manufacturing/wizard/rework_wizard.py +++ b/sf_manufacturing/wizard/rework_wizard.py @@ -24,6 +24,7 @@ class ReworkWizard(models.TransientModel): # 根据工单的加工面来显示 processing_panel_id = fields.Many2many('sf.processing.panel', string="加工面") is_reprogramming = fields.Boolean(string='申请重新编程', default=False) + is_reprogramming_readonly = fields.Boolean(string='申请重新编程(只读)', default=False) reprogramming_num = fields.Integer('重新编程次数', default=0) programming_state = fields.Selection( [('待编程', '待编程'), ('编程中', '编程中'), ('已编程', '已编程'), ('已编程未下发', '已编程未下发'), @@ -85,35 +86,36 @@ class ReworkWizard(models.TransientModel): lambda ap1: ap1.processing_panel == panel.name and ap1.handle_result == '待处理').write( {'handle_result': '已处理'}) if self.is_reprogramming is False: - if self.reprogramming_num >= 1: - self.production_id.get_new_program(panel.name) - else: - ret = {'programming_list': []} - cnc_rework = self.production_id.workorder_ids.filtered( - lambda crw: crw.processing_panel == panel.name and crw.state in ( - 'rework') and crw.routing_type == 'CNC加工') - if cnc_rework.cnc_ids: - for item_line in cnc_rework.cnc_ids: - vals = { - 'sequence_number': item_line.sequence_number, - 'program_name': item_line.program_name, - 'cutting_tool_name': item_line.cutting_tool_name, - 'cutting_tool_no': item_line.cutting_tool_no, - 'processing_type': item_line.processing_type, - 'margin_x_y': item_line.margin_x_y, - 'margin_z': item_line.margin_z, - 'depth_of_processing_z': item_line.depth_of_processing_z, - 'cutting_tool_extension_length': item_line.cutting_tool_extension_length, - 'estimated_processing_time': item_line.estimated_processing_time, - 'cutting_tool_handle_type': item_line.cutting_tool_handle_type, - 'program_path': item_line.program_path, - 'ftp_path': item_line.program_path, - 'processing_panel': panel.name, - 'program_create_date': datetime.strftime(item_line.program_create_date, - '%Y-%m-%d %H:%M:%S'), - 'remark': item_line.remark - } - ret['programming_list'].append(vals) + if self.programming_state in ['已编程', '已下发']: + if self.reprogramming_num >= 1 and self.programming_state == '已编程': + self.production_id.get_new_program(panel.name) + if self.reprogramming_num >= 0 and self.programming_state == '已下发': + ret = {'programming_list': []} + cnc_rework = self.production_id.workorder_ids.filtered( + lambda crw: crw.processing_panel == panel.name and crw.state in ( + 'rework') and crw.routing_type == 'CNC加工') + if cnc_rework.cnc_ids: + for item_line in cnc_rework.cnc_ids: + vals = { + 'sequence_number': item_line.sequence_number, + 'program_name': item_line.program_name, + 'cutting_tool_name': item_line.cutting_tool_name, + 'cutting_tool_no': item_line.cutting_tool_no, + 'processing_type': item_line.processing_type, + 'margin_x_y': item_line.margin_x_y, + 'margin_z': item_line.margin_z, + 'depth_of_processing_z': item_line.depth_of_processing_z, + 'cutting_tool_extension_length': item_line.cutting_tool_extension_length, + 'estimated_processing_time': item_line.estimated_processing_time, + 'cutting_tool_handle_type': item_line.cutting_tool_handle_type, + 'program_path': item_line.program_path, + 'ftp_path': item_line.program_path, + 'processing_panel': panel.name, + 'program_create_date': datetime.strftime(item_line.program_create_date, + '%Y-%m-%d %H:%M:%S'), + 'remark': item_line.remark + } + ret['programming_list'].append(vals) for cmm_line in cnc_rework.cmm_ids: vals = { 'sequence_number': cmm_line.sequence_number, @@ -121,35 +123,40 @@ class ReworkWizard(models.TransientModel): 'program_path': cmm_line.program_path, 'ftp_path': item_line.program_path, 'processing_panel': panel.name, - 'program_create_date': datetime.strftime(cmm_line.program_create_date, - '%Y-%m-%d %H:%M:%S') + 'program_create_date': datetime.strftime( + cmm_line.program_create_date, + '%Y-%m-%d %H:%M:%S') } ret['programming_list'].append(vals) - new_cnc_workorder = self.production_id.workorder_ids.filtered( - lambda ap1: ap1.processing_panel == panel.name and ap1.state not in ( - 'rework', 'done') and ap1.routing_type == 'CNC加工') - if not new_cnc_workorder.cnc_ids: - new_cnc_workorder.write({ - 'cnc_ids': new_cnc_workorder.cnc_ids.sudo()._json_cnc_processing(panel.name, - ret), - 'cmm_ids': new_cnc_workorder.cmm_ids.sudo()._json_cmm_program(panel.name, ret), - 'cnc_worksheet': new_cnc_workorder.cnc_worksheet}) - new_pre_workorder = self.production_id.workorder_ids.filtered(lambda - p: p.routing_type == '装夹预调' and p.processing_panel == panel.name and p.state not in ( - 'rework', 'done')) - if new_pre_workorder: - pre_rework = self.production_id.workorder_ids.filtered( - lambda pr: pr.processing_panel == panel.name and pr.state in ( - 'rework') and pr.routing_type == '装夹预调') - new_pre_workorder.write( - {'processing_drawing': pre_rework.processing_drawing}) - self.production_id.write({'state': 'progress', 'is_rework': False}) + new_cnc_workorder = self.production_id.workorder_ids.filtered( + lambda ap1: ap1.processing_panel == panel.name and ap1.state not in ( + 'rework', 'done') and ap1.routing_type == 'CNC加工') + if not new_cnc_workorder.cnc_ids: + new_cnc_workorder.write({ + 'cnc_ids': new_cnc_workorder.cnc_ids.sudo()._json_cnc_processing(panel.name, + ret), + 'cmm_ids': new_cnc_workorder.cmm_ids.sudo()._json_cmm_program(panel.name, + ret), + 'cnc_worksheet': new_cnc_workorder.cnc_worksheet}) + new_pre_workorder = self.production_id.workorder_ids.filtered(lambda + p: p.routing_type == '装夹预调' and p.processing_panel == panel.name and p.state not in ( + 'rework', 'done')) + if new_pre_workorder: + pre_rework = self.production_id.workorder_ids.filtered( + lambda pr: pr.processing_panel == panel.name and pr.state in ( + 'rework') and pr.routing_type == '装夹预调') + new_pre_workorder.write( + {'processing_drawing': pre_rework.processing_drawing}) + self.production_id.write({'state': 'progress', 'is_rework': False}) + elif self.programming_state in ['待编程', '编程中']: + self.production_id.write( + {'programming_state': '编程中', 'work_state': '编程中', 'is_rework': True}) if self.is_reprogramming is True: self.production_id.update_programming_state() self.production_id.write( {'programming_state': '编程中', 'work_state': '编程中'}) if self.production_id.state == 'progress': - self.production_id.write({'programming_state': '已编程', 'work_state': '编程中'}) + self.production_id.write({'programming_state': '已编程', 'work_state': '已编程'}) @api.onchange('production_id') def onchange_processing_panel_id(self): diff --git a/sf_manufacturing/wizard/rework_wizard_views.xml b/sf_manufacturing/wizard/rework_wizard_views.xml index 49274368..30ea50f1 100644 --- a/sf_manufacturing/wizard/rework_wizard_views.xml +++ b/sf_manufacturing/wizard/rework_wizard_views.xml @@ -25,8 +25,10 @@ decoration-danger="programming_state =='已编程'" readonly="1"/> - + +