diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index cf9708f9..7ac20df1 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -103,7 +103,8 @@ class MrpProduction(models.Model): precision_rounding=production.product_uom_id.rounding) >= 0: production.state = 'to_close' elif any( - wo.test_results == '返工' and wo.state == 'done' for wo in production.workorder_ids): + (wo.test_results == '返工' and wo.state == 'done') or wo.state == 'rework' for wo in + production.workorder_ids): production.state = 'rework' elif any(wo_state in ('progress', 'done') for wo_state in production.workorder_ids.mapped('state')): production.state = 'progress' @@ -155,27 +156,25 @@ class MrpProduction(models.Model): for production in self: production.maintenance_count = len(production.request_ids) - # 制造订单报废:编程单更新 - def updateCNC(self): + # 编程单更新 + def update_programming_state(self): try: - res = {'production_no': self.name, 'programming_no': self.programming_no, - 'order_no': self.origin} + res = {'programming_no': self.programming_no} logging.info('res=%s:' % res) configsettings = self.env['res.config.settings'].get_values() config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key']) - url = '/api/intelligent_programming/update_intelligent_programmings' + url = '/api/intelligent_programming/reset_state_again' config_url = configsettings['sf_url'] + url - res['token'] = configsettings['token'] ret = requests.post(config_url, json={}, data=res, headers=config_header) ret = ret.json() - logging.info('updateCNC-ret:%s' % ret) + logging.info('update_programming_state-ret:%s' % ret) if ret['status'] == 1: self.write({'work_state': '已编程'}) else: raise UserError(ret['message']) except Exception as e: - logging.info('updateCNC error:%s' % e) - raise UserError("更新程单失败,请联系管理员") + logging.info('update_programming_state error:%s' % e) + raise UserError("更新编程单状态失败,请联系管理员") # cnc程序获取 def fetchCNC(self, production_names): @@ -698,8 +697,9 @@ class MrpProduction(models.Model): 'res_model': 'sf.rework.wizard', 'target': 'new', 'context': { - 'default_production_id': [(6, 0, [self.id])], - 'default_product_id': self.product_id.id + 'default_production_id': self.id, + 'default_product_id': self.product_id.id, + 'default_is_reprogramming': True } } diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 9182926d..731650af 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -47,7 +47,7 @@ class ResMrpWorkOrder(models.Model): ('切割', '切割'), ('表面工艺', '表面工艺') ], string="工序类型") results = fields.Char('结果') - state = fields.Selection(selection_add=[('to be detected', "待检测")]) + state = fields.Selection(selection_add=[('to be detected', "待检测"), ('rework', '返工')]) manual_quotation = fields.Boolean('人工编程', default=False, readonly=True) @@ -820,26 +820,26 @@ class ResMrpWorkOrder(models.Model): # @api.depends('production_availability', 'blocked_by_workorder_ids', 'blocked_by_workorder_ids.state') # def _compute_state(self): - # super(ResMrpWorkOrder, self)._compute_state() - # for item in self: - # print(item.name) - # print(item.state) - # print(item.is_remanufacture) - # scrap_workorder = self.env['mrp.workorder'].search( - # [('production_id', '=', item.production_id.id), ('routing_type', '=', 'CNC加工'), - # ('state', '=', 'done'), ('test_results', 'in', ['返工', '报废'])]) - # print(scrap_workorder) - # # if item.routing_type == 'CNC加工' and item.state in ['done'] and item.test_results in ['返工', '报废']: - # if item.routing_type == '解除装夹': - # if scrap_workorder and item.state not in ['cancel']: - # item.state = 'cancel' - # elif item.routing_type == '表面工艺': - # if scrap_workorder: - # stock_move = self.env['stock.move'].search( - # [('origin', '=', item.production_id.name)]) - # stock_move.write({'state': 'cancel'}) - # item.picking_ids.write({'state': 'cancel'}) - # item.state = 'cancel' + # for workorder in self: + # if any( + # (wo.test_results == '返工' and wo.state == 'done') or wo.state == 'rework' for wo in + # production.workorder_ids): + # production.state = 'rework' + # if workorder.state == 'pending': + # if all([wo.state in ('done', 'cancel') for wo in workorder.blocked_by_workorder_ids]): + # workorder.state = 'ready' if workorder.production_id.reservation_state == 'assigned' else 'waiting' + # continue + # if workorder.state not in ('waiting', 'ready'): + # continue + # if not all([wo.state in ('done', 'cancel') for wo in workorder.blocked_by_workorder_ids]): + # workorder.state = 'pending' + # continue + # if workorder.production_id.reservation_state not in ('waiting', 'confirmed', 'assigned'): + # continue + # if workorder.production_id.reservation_state == 'assigned' and workorder.state == 'waiting': + # workorder.state = 'ready' + # elif workorder.production_id.reservation_state != 'assigned' and workorder.state == 'ready': + # workorder.state = 'waiting' # 重写工单开始按钮方法 def button_start(self): @@ -1175,24 +1175,25 @@ class CNCprocessing(models.Model): def _json_cnc_processing(self, panel, ret): cnc_processing = [] - for item in ret['programming_list']: - if item['processing_panel'] == panel and item['ftp_path'].find('.dmi') == -1: - cnc_processing.append((0, 0, { - 'sequence_number': item['sequence_number'], - 'program_name': item['program_name'], - 'cutting_tool_name': item['cutting_tool_name'], - 'cutting_tool_no': item['cutting_tool_no'], - 'processing_type': item['processing_type'], - 'margin_x_y': item['margin_x_y'], - 'margin_z': item['margin_z'], - 'depth_of_processing_z': item['depth_of_processing_z'], - 'cutting_tool_extension_length': item['cutting_tool_extension_length'], - 'cutting_tool_handle_type': item['cutting_tool_handle_type'], - 'estimated_processing_time': item['estimated_processing_time'], - 'program_path': item['ftp_path'], - 'program_create_date': datetime.strptime(item['program_create_date'], '%Y-%m-%d %H:%M:%S'), - 'remark': item['remark'] - })) + if ret is not False: + for item in ret['programming_list']: + if item['processing_panel'] == panel and item['ftp_path'].find('.dmi') == -1: + cnc_processing.append((0, 0, { + 'sequence_number': item['sequence_number'], + 'program_name': item['program_name'], + 'cutting_tool_name': item['cutting_tool_name'], + 'cutting_tool_no': item['cutting_tool_no'], + 'processing_type': item['processing_type'], + 'margin_x_y': item['margin_x_y'], + 'margin_z': item['margin_z'], + 'depth_of_processing_z': item['depth_of_processing_z'], + 'cutting_tool_extension_length': item['cutting_tool_extension_length'], + 'cutting_tool_handle_type': item['cutting_tool_handle_type'], + 'estimated_processing_time': item['estimated_processing_time'], + 'program_path': item['ftp_path'], + 'program_create_date': datetime.strptime(item['program_create_date'], '%Y-%m-%d %H:%M:%S'), + 'remark': item['remark'] + })) return cnc_processing # 根据程序名和加工面匹配到ftp里对应的Nc程序名,可优化为根据cnc_processing.program_path进行匹配 @@ -1648,12 +1649,13 @@ class CMMprogram(models.Model): def _json_cmm_program(self, panel, ret): cmm_program = [] - for item in ret['programming_list']: - if item['processing_panel'] == panel and item['ftp_path'].find('.dmi') != -1: - cmm_program.append((0, 0, { - 'sequence_number': 1, - 'program_name': item['program_name'], - 'program_path': item['ftp_path'], - 'program_create_date': datetime.strptime(item['program_create_date'], '%Y-%m-%d %H:%M:%S'), - })) + if ret is not False: + for item in ret['programming_list']: + if item['processing_panel'] == panel and item['ftp_path'].find('.dmi') != -1: + cmm_program.append((0, 0, { + 'sequence_number': 1, + 'program_name': item['program_name'], + 'program_path': item['ftp_path'], + 'program_create_date': datetime.strptime(item['program_create_date'], '%Y-%m-%d %H:%M:%S'), + })) return cmm_program diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index 42aa5891..a946eb0a 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -11,7 +11,7 @@ - + diff --git a/sf_manufacturing/wizard/rework_wizard.py b/sf_manufacturing/wizard/rework_wizard.py index 38637482..ee323680 100644 --- a/sf_manufacturing/wizard/rework_wizard.py +++ b/sf_manufacturing/wizard/rework_wizard.py @@ -12,7 +12,7 @@ class ReworkWizard(models.TransientModel): workorder_id = fields.Many2one('mrp.workorder', string='工单') product_id = fields.Many2one('product.product') - production_ids = fields.Many2many('mrp.production', string='制造订单号') + production_id = fields.Many2one('mrp.production', string='制造订单号') rework_reason = fields.Selection( [("programming", "编程"), ("cutter", "刀具"), ("clamping", "装夹"), ("operate computer", "操机"), @@ -23,17 +23,38 @@ class ReworkWizard(models.TransientModel): ('CNC加工', 'CNC加工')], string="工序类型") # 根据工单的加工面来显示 processing_panel_id = fields.Many2one('sf.processing.panel', string="加工面") + is_reprogramming = fields.Boolean(string='申请重新编程', default=False) def confirm(self): - if len(self.production_ids) == 1: + if self.is_reprogramming is True: + if self.production_id.workorder_ids: + panel_workorder = self.production_id.workorder_ids.filtered( + lambda ap: ap.processing_panel == self.processing_panel_id.name) + if panel_workorder: + panel_workorder.write({'state': 'rework'}) + product_routing_workcenter = self.env['sf.product.model.type.routing.sort'].search( + [('product_model_type_id', '=', self.production_id.product_id.product_model_type_id.id)], + order='sequence asc' + ) + workorders_values = [] + for route in product_routing_workcenter: + if route.is_repeat is True: + workorders_values.append( + self.env['mrp.workorder'].json_workorder_str(self.processing_panel_id.name, + self.production_id, route, False)) + if workorders_values: + self.production_id.write({'workorder_ids': workorders_values, 'programming_state': '编程中'}) + self.production_id._reset_work_order_sequence() + self.production_id.update_programming_state() + else: self.workorder_id.is_rework = True - self.production_ids.write({'detection_result_ids': [(0, 0, { - 'rework_reason': self.rework_reason, - 'detailed_reason': self.detailed_reason, - # 'processing_panel': self.workorder_id.processing_panel, - 'routing_type': self.workorder_id.routing_type, - 'test_results': self.workorder_id.test_results, - 'test_report': self.workorder_id.detection_report})]}) + self.production_id.write({'detection_result_ids': [(0, 0, { + 'rework_reason': self.rework_reason, + 'detailed_reason': self.detailed_reason, + # 'processing_panel': self.workorder_id.processing_panel, + 'routing_type': self.workorder_id.routing_type, + 'test_results': self.workorder_id.test_results, + 'test_report': self.workorder_id.detection_report})]}) @api.onchange('product_id') def onchange_processing_panel_id(self): @@ -50,4 +71,3 @@ class ReworkWizard(models.TransientModel): panel_ids.append(panel.id) domain = {'processing_panel_id': [('id', 'in', panel_ids)]} return {'domain': domain} - diff --git a/sf_manufacturing/wizard/rework_wizard_views.xml b/sf_manufacturing/wizard/rework_wizard_views.xml index 975004d3..d08ab1ba 100644 --- a/sf_manufacturing/wizard/rework_wizard_views.xml +++ b/sf_manufacturing/wizard/rework_wizard_views.xml @@ -6,13 +6,17 @@
- + - - - + + + +