Accept Merge Request #1117: (feature/修复无外协单和程序单 -> develop)

Merge Request: 修复无外协单和程序单

Created By: @杨金灵
Reviewed By: @马广威
Approved By: @马广威 
Accepted By: @杨金灵
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/1117
This commit is contained in:
杨金灵
2024-07-01 09:31:43 +08:00
committed by Coding
4 changed files with 74 additions and 45 deletions

View File

@@ -359,6 +359,7 @@ class MrpProduction(models.Model):
# 表面工艺工序 # 表面工艺工序
# 获取表面工艺id # 获取表面工艺id
if production.product_id.model_process_parameters_ids: 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 = [] surface_technics_arr = []
# 工序id # 工序id
route_workcenter_arr = [] route_workcenter_arr = []
@@ -373,6 +374,7 @@ class MrpProduction(models.Model):
# 用filter刷选表面工艺id'是否存在工艺类别对象里 # 用filter刷选表面工艺id'是否存在工艺类别对象里
if production_process_category: if production_process_category:
for p in production_process_category: for p in production_process_category:
logging.info('production_process_category:%s' % p.name)
production_process = p.production_process_ids.filtered( production_process = p.production_process_ids.filtered(
lambda pp: pp.id in surface_technics_arr) lambda pp: pp.id in surface_technics_arr)
if production_process: if production_process:
@@ -426,7 +428,7 @@ class MrpProduction(models.Model):
else: else:
if m == len(consecutive_workorders) - 1 and m != 0: if m == len(consecutive_workorders) - 1 and m != 0:
self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, self.env['stock.picking'].create_outcontract_picking(consecutive_workorders,
production_item) production)
if sorted_workorders[i] in consecutive_workorders: if sorted_workorders[i] in consecutive_workorders:
is_pick = True is_pick = True
consecutive_workorders = [] consecutive_workorders = []
@@ -434,21 +436,21 @@ class MrpProduction(models.Model):
# 当前面的连续工序生成对应的外协出入库单再生成当前工序的外协出入库单 # 当前面的连续工序生成对应的外协出入库单再生成当前工序的外协出入库单
if is_pick is False: if is_pick is False:
self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i],
production_item) production)
if m == len(consecutive_workorders) - 1 and m != 0: if m == len(consecutive_workorders) - 1 and m != 0:
self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, self.env['stock.picking'].create_outcontract_picking(consecutive_workorders,
production_item) production)
if sorted_workorders[i] in consecutive_workorders: if sorted_workorders[i] in consecutive_workorders:
is_pick = True is_pick = True
consecutive_workorders = [] consecutive_workorders = []
m = 0 m = 0
if m == len(consecutive_workorders) - 1 and 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 is_pick is False and m == 0:
if len(sorted_workorders) == 1: 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: 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: for workorder in production.workorder_ids:
workorder.duration_expected = workorder._get_duration_expected() workorder.duration_expected = workorder._get_duration_expected()
@@ -655,7 +657,7 @@ class MrpProduction(models.Model):
for production in self: for production in self:
production.write({ production.write({
'date_finished': fields.Datetime.now(), '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', 'priority': '0',
'is_locked': True, 'is_locked': True,
'state': 'done', 'state': 'done',

View File

@@ -202,6 +202,7 @@ class ResMrpWorkOrder(models.Model):
[("programming", "编程"), ("clamping", "返工"), ("cutter", "刀具"), ("operate computer", "操机"), [("programming", "编程"), ("clamping", "返工"), ("cutter", "刀具"), ("operate computer", "操机"),
("technology", "工艺"), ("customer redrawing", "客户改图"), ("other", "其他"), ], string="原因", tracking=True) ("technology", "工艺"), ("customer redrawing", "客户改图"), ("other", "其他"), ], string="原因", tracking=True)
detailed_reason = fields.Text('详细原因') detailed_reason = fields.Text('详细原因')
# is_send_program_again = fields.Boolean(string='是否重新下发NC程序', default=False) # is_send_program_again = fields.Boolean(string='是否重新下发NC程序', default=False)
@api.onchange('rfid_code') @api.onchange('rfid_code')
@@ -861,7 +862,7 @@ class ResMrpWorkOrder(models.Model):
('location_dest_id', '=', self.env['stock.location'].search( ('location_dest_id', '=', self.env['stock.location'].search(
[('barcode', 'ilike', 'VL-SPOC')]).id), [('barcode', 'ilike', 'VL-SPOC')]).id),
('origin', '=', self.production_id.name)]) ('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: if purchase and move_out:
move_out.write({'state': 'assigned'}) move_out.write({'state': 'assigned'})
self.env['stock.move.line'].create(move_out.get_move_line(purchase, self)) 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_old = rfid_code
workorder.rfid_code = '' workorder.rfid_code = ''
if is_production_id is True and record.routing_type in ['解除装夹', '表面工艺']: 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: for move_raw_id in record.production_id.move_raw_ids:
move_raw_id.quantity_done = move_raw_id.product_uom_qty move_raw_id.quantity_done = move_raw_id.product_uom_qty
record.process_state = '已完工' record.process_state = '已完工'

View File

@@ -204,14 +204,14 @@ class StockRule(models.Model):
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create( productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
productions_values) 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() # 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 \ 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_dest_ids.procure_method != 'make_to_order' and not

View File

@@ -28,7 +28,7 @@ class Sf_Mrs_Connect(http.Controller):
request.env.ref("base.user_admin")).search( request.env.ref("base.user_admin")).search(
[('programming_no', '=', ret['programming_no'])]) [('programming_no', '=', ret['programming_no'])])
if productions: if productions:
# 拉取所有加工面的程序文件 # # 拉取所有加工面的程序文件
for r in ret['processing_panel'].split(','): for r in ret['processing_panel'].split(','):
program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r) program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r)
if os.path.exists(program_path_tmp_r): if os.path.exists(program_path_tmp_r):
@@ -48,40 +48,65 @@ class Sf_Mrs_Connect(http.Controller):
if not production.workorder_ids: if not production.workorder_ids:
production.product_id.model_processing_panel = ret['processing_panel'] production.product_id.model_processing_panel = ret['processing_panel']
production._create_workorder(ret) production._create_workorder(ret)
else: # else:
for panel in ret['processing_panel'].split(','): # for panel in ret['processing_panel'].split(','):
# 查询状态为进行中且工序类型为CNC加工的工单 # # 查询状态为进行中且工序类型为CNC加工的工单
cnc_workorder = production.workorder_ids.filtered( # cnc_workorder = production.workorder_ids.filtered(
lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', # lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done',
'cancel'] and ac.processing_panel == panel) # 'cancel'] and ac.processing_panel == panel)
if cnc_workorder: # if cnc_workorder:
if cnc_workorder.cnc_ids: # if cnc_workorder.cnc_ids:
cnc_workorder.cmm_ids.sudo().unlink() # cnc_workorder.cmm_ids.sudo().unlink()
cnc_workorder.cnc_ids.sudo().unlink() # cnc_workorder.cnc_ids.sudo().unlink()
request.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan( # request.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan(
production) # production)
# program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', # # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test',
# panel) # # panel)
program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', 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) # logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel)
files_panel = os.listdir(program_path_tmp_panel) # files_panel = os.listdir(program_path_tmp_panel)
if files_panel: # if files_panel:
for file in files_panel: # for file in files_panel:
file_extension = os.path.splitext(file)[1] # file_extension = os.path.splitext(file)[1]
logging.info('file_extension:%s' % file_extension) # logging.info('file_extension:%s' % file_extension)
if file_extension.lower() == '.pdf': # if file_extension.lower() == '.pdf':
panel_file_path = os.path.join(program_path_tmp_panel, file) # panel_file_path = os.path.join(program_path_tmp_panel, file)
logging.info('panel_file_path:%s' % panel_file_path) # logging.info('panel_file_path:%s' % panel_file_path)
cnc_workorder.write( # cnc_workorder.write(
{'cnc_ids': cnc_workorder.cnc_ids.sudo()._json_cnc_processing(panel, ret), # {'cnc_ids': cnc_workorder.cnc_ids.sudo()._json_cnc_processing(panel, ret),
'cmm_ids': cnc_workorder.cmm_ids.sudo()._json_cmm_program(panel, ret), # 'cmm_ids': cnc_workorder.cmm_ids.sudo()._json_cmm_program(panel, ret),
'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())}) # 'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())})
pre_workorder = production.workorder_ids.filtered( # pre_workorder = production.workorder_ids.filtered(
lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', # lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done',
'cancel'] and ap.processing_panel == panel) # 'cancel'] and ap.processing_panel == panel)
if pre_workorder: # if pre_workorder:
pre_workorder.write( # pre_workorder.write(
{'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) # {'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': '已编程'}) productions.write({'programming_state': '已编程', 'work_state': '已编程'})
cnc_program_ids = [item.id for item in productions] cnc_program_ids = [item.id for item in productions]
workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search( workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search(