diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 544f6587..3a49c2fa 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -359,6 +359,7 @@ class MrpProduction(models.Model): # 表面工艺工序 # 获取表面工艺id if production.product_id.model_process_parameters_ids: + logging.info('model_process_parameters_ids:%s' % production.product_id.model_process_parameters_ids) surface_technics_arr = [] # 工序id route_workcenter_arr = [] @@ -373,6 +374,7 @@ class MrpProduction(models.Model): # 用filter刷选表面工艺id'是否存在工艺类别对象里 if production_process_category: for p in production_process_category: + logging.info('production_process_category:%s' % p.name) production_process = p.production_process_ids.filtered( lambda pp: pp.id in surface_technics_arr) if production_process: @@ -426,7 +428,7 @@ class MrpProduction(models.Model): else: if m == len(consecutive_workorders) - 1 and m != 0: self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, - production_item) + production) if sorted_workorders[i] in consecutive_workorders: is_pick = True consecutive_workorders = [] @@ -434,21 +436,21 @@ class MrpProduction(models.Model): # 当前面的连续工序生成对应的外协出入库单再生成当前工序的外协出入库单 if is_pick is False: self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], - production_item) + production) if m == len(consecutive_workorders) - 1 and m != 0: self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, - production_item) + production) 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) + self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production) if is_pick is False and m == 0: if len(sorted_workorders) == 1: - self.env['stock.picking'].create_outcontract_picking(sorted_workorders, production_item) + self.env['stock.picking'].create_outcontract_picking(sorted_workorders, production) else: - self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], production_item) + self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], production) for workorder in production.workorder_ids: workorder.duration_expected = workorder._get_duration_expected() @@ -655,7 +657,7 @@ class MrpProduction(models.Model): for production in self: production.write({ 'date_finished': fields.Datetime.now(), - 'product_qty': production.qty_produced, + 'product_qty': production.qty_produced if production.qty_produced < 1 else production.product_qty, 'priority': '0', 'is_locked': True, 'state': 'done', diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index f9e7bd80..ac0ab67a 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -202,6 +202,7 @@ class ResMrpWorkOrder(models.Model): [("programming", "编程"), ("clamping", "返工"), ("cutter", "刀具"), ("operate computer", "操机"), ("technology", "工艺"), ("customer redrawing", "客户改图"), ("other", "其他"), ], string="原因", tracking=True) detailed_reason = fields.Text('详细原因') + # is_send_program_again = fields.Boolean(string='是否重新下发NC程序', default=False) @api.onchange('rfid_code') @@ -861,7 +862,7 @@ class ResMrpWorkOrder(models.Model): ('location_dest_id', '=', self.env['stock.location'].search( [('barcode', 'ilike', 'VL-SPOC')]).id), ('origin', '=', self.production_id.name)]) - purchase = self.env['purchase.order'].search([('origin', '=', self.production_id.name)]) + purchase = self.env['purchase.order'].search([('origin', 'ilike', self.production_id.name)]) if purchase and move_out: move_out.write({'state': 'assigned'}) self.env['stock.move.line'].create(move_out.get_move_line(purchase, self)) @@ -1010,6 +1011,7 @@ class ResMrpWorkOrder(models.Model): workorder.rfid_code_old = rfid_code workorder.rfid_code = '' if is_production_id is True and record.routing_type in ['解除装夹', '表面工艺']: + logging.info('product_qty:%s' % record.production_id.product_qty) for move_raw_id in record.production_id.move_raw_ids: move_raw_id.quantity_done = move_raw_id.product_uom_qty record.process_state = '已完工' diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index 08350af2..9e826fb5 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -204,14 +204,14 @@ class StockRule(models.Model): productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create( productions_values) - # self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) + self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) ''' 创建工单 ''' # productions._create_workorder() # - # self.env['stock.move'].sudo().create(productions._get_moves_finished_values()) + self.env['stock.move'].sudo().create(productions._get_moves_finished_values()) 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 diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py index 4666fd99..f32dedea 100644 --- a/sf_mrs_connect/controllers/controllers.py +++ b/sf_mrs_connect/controllers/controllers.py @@ -28,7 +28,7 @@ class Sf_Mrs_Connect(http.Controller): request.env.ref("base.user_admin")).search( [('programming_no', '=', ret['programming_no'])]) if productions: - # 拉取所有加工面的程序文件 + # # 拉取所有加工面的程序文件 for r in ret['processing_panel'].split(','): program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r) if os.path.exists(program_path_tmp_r): @@ -48,40 +48,65 @@ class Sf_Mrs_Connect(http.Controller): if not production.workorder_ids: production.product_id.model_processing_panel = ret['processing_panel'] production._create_workorder(ret) - else: - for panel in ret['processing_panel'].split(','): - # 查询状态为进行中且工序类型为CNC加工的工单 - cnc_workorder = production.workorder_ids.filtered( - lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', - 'cancel'] and ac.processing_panel == panel) - if cnc_workorder: - if cnc_workorder.cnc_ids: - cnc_workorder.cmm_ids.sudo().unlink() - cnc_workorder.cnc_ids.sudo().unlink() - request.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan( - production) - # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', - # panel) - program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', panel) - logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel) - files_panel = os.listdir(program_path_tmp_panel) - if files_panel: - for file in files_panel: - file_extension = os.path.splitext(file)[1] - logging.info('file_extension:%s' % file_extension) - if file_extension.lower() == '.pdf': - panel_file_path = os.path.join(program_path_tmp_panel, file) - logging.info('panel_file_path:%s' % panel_file_path) - cnc_workorder.write( - {'cnc_ids': cnc_workorder.cnc_ids.sudo()._json_cnc_processing(panel, ret), - 'cmm_ids': cnc_workorder.cmm_ids.sudo()._json_cmm_program(panel, ret), - 'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())}) - pre_workorder = production.workorder_ids.filtered( - lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', - 'cancel'] and ap.processing_panel == panel) - if pre_workorder: - pre_workorder.write( - {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) + # else: + # for panel in ret['processing_panel'].split(','): + # # 查询状态为进行中且工序类型为CNC加工的工单 + # cnc_workorder = production.workorder_ids.filtered( + # lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', + # 'cancel'] and ac.processing_panel == panel) + # if cnc_workorder: + # if cnc_workorder.cnc_ids: + # cnc_workorder.cmm_ids.sudo().unlink() + # cnc_workorder.cnc_ids.sudo().unlink() + # request.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan( + # production) + # # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', + # # panel) + # program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', panel) + # logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel) + # files_panel = os.listdir(program_path_tmp_panel) + # if files_panel: + # for file in files_panel: + # file_extension = os.path.splitext(file)[1] + # logging.info('file_extension:%s' % file_extension) + # if file_extension.lower() == '.pdf': + # panel_file_path = os.path.join(program_path_tmp_panel, file) + # logging.info('panel_file_path:%s' % panel_file_path) + # cnc_workorder.write( + # {'cnc_ids': cnc_workorder.cnc_ids.sudo()._json_cnc_processing(panel, ret), + # 'cmm_ids': cnc_workorder.cmm_ids.sudo()._json_cmm_program(panel, ret), + # 'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())}) + # pre_workorder = production.workorder_ids.filtered( + # lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', + # 'cancel'] and ap.processing_panel == panel) + # if pre_workorder: + # pre_workorder.write( + # {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) + for panel in ret['processing_panel'].split(','): + # 查询状态为进行中且工序类型为CNC加工的工单 + cnc_workorder = productions.workorder_ids.filtered( + lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', + 'cancel'] and ac.processing_panel == panel) + if cnc_workorder: + # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', + # panel) + program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', panel) + logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel) + files_panel = os.listdir(program_path_tmp_panel) + if files_panel: + for file in files_panel: + file_extension = os.path.splitext(file)[1] + logging.info('file_extension:%s' % file_extension) + if file_extension.lower() == '.pdf': + panel_file_path = os.path.join(program_path_tmp_panel, file) + logging.info('panel_file_path:%s' % panel_file_path) + cnc_workorder.write({'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())}) + pre_workorder = productions.workorder_ids.filtered( + lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', + 'cancel'] and ap.processing_panel == panel) + if pre_workorder: + pre_workorder.write( + {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) productions.write({'programming_state': '已编程', 'work_state': '已编程'}) cnc_program_ids = [item.id for item in productions] workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search(