diff --git a/sf_manufacturing/controllers/controllers.py b/sf_manufacturing/controllers/controllers.py index ac7f77b3..0a1f4cb6 100644 --- a/sf_manufacturing/controllers/controllers.py +++ b/sf_manufacturing/controllers/controllers.py @@ -466,7 +466,6 @@ class Manufacturing_Connect(http.Controller): order='id asc') if workpiece_delivery: for wd in workpiece_delivery: - logging.info('wd.production_id:%s' % wd.production_id.name) if wd.workorder_id.state == 'done' and wd.production_id.production_line_state == '待上产线': logging.info( 'wd.production_line_state:%s' % wd.production_id.production_line_state) @@ -519,7 +518,6 @@ class Manufacturing_Connect(http.Controller): order='id asc') if workpiece_delivery: for wd in workpiece_delivery: - logging.info('wd.production_id:%s' % wd.production_id.name) if wd.workorder_id.state == 'done' and wd.production_id.production_line_state == '已上产线': logging.info( 'wd.production_line_state:%s' % wd.production_id.production_line_state) diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 9df8ff69..3afef01d 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -315,7 +315,7 @@ class MrpProduction(models.Model): production.fetchCNC(', '.join(product_id_to_production_names[production.product_id.id])) else: production.write({'programming_no': production_programming.programming_no, - 'programming_state': '编程中'}) + 'programming_state': '已编程' if production_programming.programming_state == '已编程' else '编程中'}) # # 根据加工面板的面数及对应的工序模板生成工单 i = 0 processing_panel_len = len(production.product_id.model_processing_panel.split(',')) @@ -406,20 +406,15 @@ class MrpProduction(models.Model): # 工单排序 def _reset_work_order_sequence1(self, k): - sequen = 0 for rec in self: - current_sequence = 10 + cnc_workorder = rec.workorder_ids.filtered(lambda wo: wo.name == "CNC加工") + cnc_back_workorder = rec.workorder_ids.filtered(lambda wo: wo.name == "CNC加工(返工)") for work in rec.workorder_ids: - work.sequence = current_sequence - current_sequence += 10 - if work.name == '后置三元质量检测' and work.processing_panel == k: - sequen = work.sequence - - for work in rec.workorder_ids: - if work.name == '后置三元质量检测(返工)' and work.processing_panel == k: - work.sequence = sequen + 2 - if work.name == 'CNC加工(返工)' and work.processing_panel == k: - work.sequence = sequen + 1 + if work.name == cnc_workorder.name and work.processing_panel == k: + cnc_back_workorder.write({'sequence': work.sequence + 1}) + print(cnc_back_workorder.sequence) + elif work.routing_type not in ['装夹预调'] and work != cnc_back_workorder: + work.sequence += 1 # 在制造订单上新增工单 def _create_workorder1(self, k): @@ -459,13 +454,7 @@ class MrpProduction(models.Model): order='sequence asc' ) i += 1 - for route in routingworkcenter: - - # if route.routing_type == '后置三元质量检测': - # workorders_values.append( - # self.env['mrp.workorder'].json_workorder_str1(k, production, route) - # ) if route.routing_type == 'CNC加工': workorders_values.append( self.env['mrp.workorder'].json_workorder_str1(k, production, route)) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 522c8c02..743f060c 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -677,13 +677,59 @@ class ResMrpWorkOrder(models.Model): productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company( self.production_id.company_id).create( values) - self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) + # self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) self.env['stock.move'].sudo().create(productions._get_moves_finished_values()) productions._create_workorder() productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \ ( p.move_dest_ids.procure_method != 'make_to_order' and not p.move_raw_ids and not p.workorder_ids)).action_confirm() + for production_item in productions: + process_parameter_workorder = self.env['mrp.workorder'].search( + [('surface_technics_parameters_id', '!=', False), ('production_id', '=', production_item.id), + ('is_subcontract', '=', True)]) + if process_parameter_workorder: + is_pick = False + consecutive_workorders = [] + m = 0 + sorted_workorders = sorted(process_parameter_workorder, key=lambda w: w.id) + for i in range(len(sorted_workorders) - 1): + if m == 0: + is_pick = False + if sorted_workorders[i].supplier_id.id == sorted_workorders[i + 1].supplier_id.id and \ + sorted_workorders[i].is_subcontract == sorted_workorders[i + 1].is_subcontract and \ + sorted_workorders[i].id == sorted_workorders[i + 1].id - 1: + if sorted_workorders[i] not in consecutive_workorders: + consecutive_workorders.append(sorted_workorders[i]) + consecutive_workorders.append(sorted_workorders[i + 1]) + m += 1 + continue + else: + if m == len(consecutive_workorders) - 1 and m != 0: + self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, + production_item) + if sorted_workorders[i] in consecutive_workorders: + is_pick = True + consecutive_workorders = [] + m = 0 + # 当前面的连续工序生成对应的外协出入库单再生成当前工序的外协出入库单 + if is_pick is False: + self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], + production_item) + if m == len(consecutive_workorders) - 1 and m != 0: + self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, + production_item) + if sorted_workorders[i] in consecutive_workorders: + is_pick = True + consecutive_workorders = [] + m = 0 + if m == len(consecutive_workorders) - 1 and m != 0: + self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production_item) + if is_pick is False and m == 0: + if len(sorted_workorders) == 1: + self.env['stock.picking'].create_outcontract_picking(sorted_workorders, production_item) + else: + self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], production_item) for production in productions: origin_production = production.move_dest_ids and production.move_dest_ids[ @@ -704,6 +750,28 @@ class ResMrpWorkOrder(models.Model): 'mail.message_origin_link', values={'self': production, 'origin': origin_production}, subtype_id=self.env.ref('mail.mt_note').id) + + ''' + 创建生产计划 + ''' + # 工单耗时 + workorder_duration = 0 + for workorder in productions.workorder_ids: + workorder_duration += workorder.duration_expected + + sale_order = self.env['sale.order'].sudo().search([('name', '=', productions.origin)]) + if sale_order: + # sale_order.write({'schedule_status': 'to schedule'}) + self.env['sf.production.plan'].sudo().with_company(self.production_id.company_id).create({ + 'name': productions.name, + 'order_deadline': sale_order.deadline_of_delivery, + 'production_id': productions.id, + 'date_planned_start': productions.date_planned_start, + 'origin': productions.origin, + 'product_qty': productions.product_qty, + 'product_id': productions.product_id.id, + 'state': 'draft', + }) if self.test_results == '返工': productions = self.production_id # self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) @@ -720,7 +788,6 @@ class ResMrpWorkOrder(models.Model): 'name': '%s(返工)' % route.route_workcenter_id.name, 'processing_panel': k, 'routing_type': route.routing_type, - 'work_state': '' if not route.routing_type == '获取CNC加工程序' else '待发起', 'workcenter_id': self.env['mrp.routing.workcenter'].get_workcenter(route.workcenter_ids.ids, route.routing_type, production.product_id), @@ -728,10 +795,38 @@ class ResMrpWorkOrder(models.Model): 'date_planned_finished': datetime.now() + timedelta(days=1), 'duration_expected': 60, 'duration': 0, - + 'manual_quotation': production.workorder_ids.filtered( + lambda t: t.routing_type == 'CNC加工').manual_quotation, + 'rfid_code': production.workorder_ids.filtered(lambda t: t.routing_type == 'CNC加工').rfid_code, + 'cnc_ids': production.workorder_ids.filtered(lambda t: t.routing_type == 'CNC加工').cnc_ids, + 'cmm_ids': production.workorder_ids.filtered(lambda t: t.routing_type == 'CNC加工').cmm_ids, }] return workorders_values_str + @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: + scrap_workorder = self.env['mrp.workorder'].search( + [('production_id', '=', item.production_id.id), ('routing_type', '=', 'CNC加工'), + ('state', '=', 'done'), ('is_remanufacture', '=', True)]) + print(item.name) + print(item.state) + if item.name == 'CNC加工(返工)' and item.state not in ['ready', 'progress', 'done']: + item.state = 'ready' + if item.routing_type == '解除装夹': + last_workorder = self.env['mrp.workorder'].search( + [('production_id', '=', item.production_id.id), ('name', '=', 'CNC加工(返工)'), + ('state', '!=', 'done')]) + if item.state != 'pending': + if last_workorder: + item.state = 'pending' + if scrap_workorder: + item.state = 'cancel' + elif item.routing_type == '表面工艺': + if scrap_workorder: + item.state = 'cancel' + # 重写工单开始按钮方法 def button_start(self): if self.routing_type == '装夹预调': @@ -895,6 +990,8 @@ class ResMrpWorkOrder(models.Model): record.write({ 'date_planned_finished': tem_date_planned_finished # 保持原值 }) + if record.routing_type == 'CNC加工' and record.test_results in ['返工', '报废']: + record.recreateManufacturingOrWorkerOrder() is_production_id = True for workorder in record.production_id.workorder_ids: if workorder.state != 'done': @@ -964,7 +1061,7 @@ class CNCprocessing(models.Model): _order = 'sequence_number,id' cnc_id = fields.Many2one('ir.attachment') - sequence_number = fields.Char('序号') + sequence_number = fields.Integer('序号') program_name = fields.Char('程序名') functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型') cutting_tool_name = fields.Char('刀具名称') @@ -1026,6 +1123,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 @@ -1233,6 +1332,8 @@ class WorkPieceDelivery(models.Model): def create(self, vals): if vals.get('name', '/') == '/' or vals.get('name', '/') is False: vals['name'] = self.env['ir.sequence'].next_by_code('sf.workpiece.delivery') or '/' + else: + vals['type'] = '运送空料架' obj = super(WorkPieceDelivery, self).create(vals) return obj @@ -1416,7 +1517,7 @@ class WorkPieceDelivery(models.Model): 'task_delivery_time': fields.Datetime.now(), 'status': '待配送' }) - if delivery_item == "上产线": + if delivery_item.type == "上产线": delivery_item.workorder_id.write({'is_delivery': True}) else: raise UserError(ret['message']) diff --git a/sf_manufacturing/views/agv_setting_views.xml b/sf_manufacturing/views/agv_setting_views.xml index 42662e2c..9a4bf25e 100644 --- a/sf_manufacturing/views/agv_setting_views.xml +++ b/sf_manufacturing/views/agv_setting_views.xml @@ -36,7 +36,7 @@ - + diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index 94f469ea..5976915b 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -80,7 +80,7 @@ tree,form - + current [('state', '!=', 'cancel'),('schedule_state', '=', '已排')] @@ -477,7 +477,7 @@ - + @@ -618,7 +618,6 @@ - @@ -668,14 +667,18 @@ 空料架配送 sf.workpiece.delivery - +
- - - - + + + + +