优化制造订单报废
This commit is contained in:
@@ -278,7 +278,7 @@ class MrpProduction(models.Model):
|
|||||||
|
|
||||||
@api.depends(
|
@api.depends(
|
||||||
'move_raw_ids.state', 'move_raw_ids.quantity_done', 'move_finished_ids.state', 'tool_state',
|
'move_raw_ids.state', 'move_raw_ids.quantity_done', 'move_finished_ids.state', 'tool_state',
|
||||||
'workorder_ids.state', 'product_qty', 'qty_producing', 'schedule_state')
|
'workorder_ids.state', 'product_qty', 'qty_producing', 'schedule_state', 'programming_state')
|
||||||
def _compute_state(self):
|
def _compute_state(self):
|
||||||
for production in self:
|
for production in self:
|
||||||
if not production.state or not production.product_uom_id:
|
if not production.state or not production.product_uom_id:
|
||||||
@@ -680,7 +680,8 @@ class MrpProduction(models.Model):
|
|||||||
if production.product_id.categ_id.type in ['成品', '坯料']:
|
if production.product_id.categ_id.type in ['成品', '坯料']:
|
||||||
# # 根据工序设计生成工单
|
# # 根据工序设计生成工单
|
||||||
for route in production.technology_design_ids:
|
for route in production.technology_design_ids:
|
||||||
workorder_has = self.env['mrp.workorder'].search([('name', '=', route.route_id.name)])
|
workorder_has = self.env['mrp.workorder'].search(
|
||||||
|
[('name', '=', route.route_id.name), ('production_id', '=', production.id)])
|
||||||
if not workorder_has:
|
if not workorder_has:
|
||||||
if route.route_id.routing_type not in ['表面工艺']:
|
if route.route_id.routing_type not in ['表面工艺']:
|
||||||
workorders_values.append(
|
workorders_values.append(
|
||||||
@@ -692,16 +693,6 @@ class MrpProduction(models.Model):
|
|||||||
self.env[
|
self.env[
|
||||||
'mrp.workorder']._json_workorder_surface_process_str(
|
'mrp.workorder']._json_workorder_surface_process_str(
|
||||||
production, route, product_production_process.seller_ids[0].partner_id.id))
|
production, route, product_production_process.seller_ids[0].partner_id.id))
|
||||||
# elif production.product_id.categ_id.type == '坯料':
|
|
||||||
# embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search(
|
|
||||||
# [('embryo_model_type_id', '=', production.product_id.embryo_model_type_id.id)],
|
|
||||||
# order='sequence asc'
|
|
||||||
# )
|
|
||||||
# for route_embryo in embryo_routing_workcenter:
|
|
||||||
# workorder_embryo_has = self.env['mrp.workorder'].search([('name', '=', route_embryo.route_id.name)])
|
|
||||||
# if not workorder_embryo_has:
|
|
||||||
# workorders_values.append(
|
|
||||||
# self.env['mrp.workorder'].json_workorder_str('', production, route_embryo))
|
|
||||||
production.workorder_ids = workorders_values
|
production.workorder_ids = workorders_values
|
||||||
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()
|
||||||
@@ -1269,6 +1260,7 @@ class MrpProduction(models.Model):
|
|||||||
重新生成制造订单
|
重新生成制造订单
|
||||||
"""
|
"""
|
||||||
if self.is_scrap is True:
|
if self.is_scrap is True:
|
||||||
|
technology_design_values = []
|
||||||
procurement_requests = []
|
procurement_requests = []
|
||||||
sale_order = self.env['sale.order'].sudo().search([('name', '=', self.origin)])
|
sale_order = self.env['sale.order'].sudo().search([('name', '=', self.origin)])
|
||||||
values = self.env['mrp.production'].create_production1_values(self)
|
values = self.env['mrp.production'].create_production1_values(self)
|
||||||
@@ -1299,11 +1291,13 @@ class MrpProduction(models.Model):
|
|||||||
[('origin', '=', self.origin)], order='id desc', limit=1)
|
[('origin', '=', self.origin)], order='id desc', limit=1)
|
||||||
move = self.env['stock.move'].search([('origin', '=', productions.name)], order='id desc')
|
move = self.env['stock.move'].search([('origin', '=', productions.name)], order='id desc')
|
||||||
for mo in move:
|
for mo in move:
|
||||||
|
domain = []
|
||||||
if mo.procure_method == 'make_to_order' and mo.name != productions.name:
|
if mo.procure_method == 'make_to_order' and mo.name != productions.name:
|
||||||
if mo.name == '/':
|
if mo.name == '/':
|
||||||
domain = [('barcode', '=', 'WH-PC'), ('sequence_code', '=', 'PC')]
|
domain = [('barcode', '=', 'WH-PC'), ('sequence_code', '=', 'PC')]
|
||||||
elif mo.name == '拉':
|
elif mo.name == '拉':
|
||||||
domain = [('barcode', '=', 'WH-INTERNAL'), ('sequence_code', '=', 'INT')]
|
domain = [('barcode', '=', 'WH-INTERNAL'), ('sequence_code', '=', 'INT')]
|
||||||
|
if domain:
|
||||||
picking_type = self.env['stock.picking.type'].search(domain)
|
picking_type = self.env['stock.picking.type'].search(domain)
|
||||||
mo.write({'picking_type_id': picking_type.id})
|
mo.write({'picking_type_id': picking_type.id})
|
||||||
mo._assign_picking()
|
mo._assign_picking()
|
||||||
@@ -1355,10 +1349,72 @@ class MrpProduction(models.Model):
|
|||||||
if purchase_orders.origin.find(productions.name) == -1:
|
if purchase_orders.origin.find(productions.name) == -1:
|
||||||
purchase_orders.origin += ',' + productions.name
|
purchase_orders.origin += ',' + productions.name
|
||||||
if item['is_reprogramming'] is False:
|
if item['is_reprogramming'] is False:
|
||||||
productions._create_workorder(item)
|
|
||||||
productions.programming_state = '已编程'
|
productions.programming_state = '已编程'
|
||||||
else:
|
else:
|
||||||
productions.programming_state = '编程中'
|
productions.programming_state = '编程中'
|
||||||
|
if not technology_design_values:
|
||||||
|
i = 0
|
||||||
|
if self.product_id.categ_id.type == '成品':
|
||||||
|
# 根据加工面板的面数及成品工序模板生成工序设计
|
||||||
|
for k in (self.product_id.model_processing_panel.split(',')):
|
||||||
|
if self.production_type == '自动化产线加工':
|
||||||
|
product_routing_workcenter = self.env['sf.product.model.type.routing.sort'].search(
|
||||||
|
[('product_model_type_id', '=',
|
||||||
|
self.product_id.product_model_type_id.id)],
|
||||||
|
order='sequence asc'
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
product_routing_workcenter = self.env[
|
||||||
|
'sf.manual.product.model.type.routing.sort'].search(
|
||||||
|
[('manual_product_model_type_id', '=',
|
||||||
|
self.product_id.product_model_type_id.id)],
|
||||||
|
order='sequence asc'
|
||||||
|
)
|
||||||
|
for route in product_routing_workcenter:
|
||||||
|
i += 1
|
||||||
|
technology_design_values.append(
|
||||||
|
self.env['sf.technology.design'].json_technology_design_str(k, route, i, False))
|
||||||
|
elif self.product_id.categ_id.type == '坯料':
|
||||||
|
i = 0
|
||||||
|
embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search(
|
||||||
|
[('embryo_model_type_id', '=', self.product_id.embryo_model_type_id.id)],
|
||||||
|
order='sequence asc'
|
||||||
|
)
|
||||||
|
for route_embryo in embryo_routing_workcenter:
|
||||||
|
i += 1
|
||||||
|
technology_design_values.append(
|
||||||
|
self.env['sf.technology.design'].json_technology_design_str(False, route_embryo, i,
|
||||||
|
False))
|
||||||
|
surface_technics_arr = []
|
||||||
|
route_workcenter_arr = []
|
||||||
|
for item in self.product_id.product_model_type_id.surface_technics_routing_tmpl_ids:
|
||||||
|
if item.route_workcenter_id.surface_technics_id.id:
|
||||||
|
for process_param in self.product_id.model_process_parameters_ids:
|
||||||
|
if item.route_workcenter_id.surface_technics_id == process_param.process_id:
|
||||||
|
surface_technics_arr.append(
|
||||||
|
item.route_workcenter_id.surface_technics_id.id)
|
||||||
|
route_workcenter_arr.append(item.route_workcenter_id.id)
|
||||||
|
if surface_technics_arr:
|
||||||
|
production_process = self.env['sf.production.process'].search(
|
||||||
|
[('id', 'in', surface_technics_arr)],
|
||||||
|
order='sequence asc'
|
||||||
|
)
|
||||||
|
for p in production_process:
|
||||||
|
# logging.info('production_process:%s' % p.name)
|
||||||
|
process_parameter = self.product_id.model_process_parameters_ids.filtered(
|
||||||
|
lambda pm: pm.process_id.id == p.id)
|
||||||
|
if process_parameter:
|
||||||
|
i += 1
|
||||||
|
route_production_process = self.env[
|
||||||
|
'mrp.routing.workcenter'].search(
|
||||||
|
[('surface_technics_id', '=', p.id),
|
||||||
|
('id', 'in', route_workcenter_arr)])
|
||||||
|
technology_design_values.append(
|
||||||
|
self.env['sf.technology.design'].json_technology_design_str(False,
|
||||||
|
route_production_process,
|
||||||
|
i,
|
||||||
|
process_parameter))
|
||||||
|
productions.technology_design_ids = technology_design_values
|
||||||
return productions
|
return productions
|
||||||
|
|
||||||
# 在之前的销售单上重新生成制造订单
|
# 在之前的销售单上重新生成制造订单
|
||||||
|
|||||||
@@ -1016,10 +1016,13 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
if workorder.state == 'pending':
|
if workorder.state == 'pending':
|
||||||
if all([wo.state in ('done', 'cancel') for wo in workorder.blocked_by_workorder_ids]):
|
if all([wo.state in ('done', 'cancel') for wo in workorder.blocked_by_workorder_ids]):
|
||||||
if workorder.production_id.reservation_state == 'assigned' and workorder.production_id.schedule_state == '已排':
|
if workorder.production_id.reservation_state == 'assigned' and workorder.production_id.schedule_state == '已排':
|
||||||
if (workorder.sequence == 1 and not workorder.blocked_by_workorder_ids) or (
|
if ((workorder.sequence == 1 and not workorder.blocked_by_workorder_ids)
|
||||||
workorder.blocked_by_workorder_ids.state in ('done', 'cancel')) or (
|
or (workorder.blocked_by_workorder_ids.state in ('done', 'cancel')
|
||||||
previous_workorder.state in (
|
and workorder.blocked_by_workorder_ids.test_results not in ['报废', '返工'])
|
||||||
'done', 'cancel') and not workorder.blocked_by_workorder_ids):
|
or (previous_workorder.state in ('done', 'cancel')
|
||||||
|
and not workorder.blocked_by_workorder_ids
|
||||||
|
and previous_workorder.test_results not in ['报废', '返工'])
|
||||||
|
):
|
||||||
workorder.state = 'ready'
|
workorder.state = 'ready'
|
||||||
continue
|
continue
|
||||||
if workorder.production_id.schedule_state == '未排' and workorder.state in ('waiting', 'ready'):
|
if workorder.production_id.schedule_state == '未排' and workorder.state in ('waiting', 'ready'):
|
||||||
@@ -1050,12 +1053,15 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
for workorder in self:
|
for workorder in self:
|
||||||
# 如果工单的工序没有进行排序则跳出循环
|
# 如果工单的工序没有进行排序则跳出循环
|
||||||
if workorder.production_id.workorder_ids.filtered(lambda wk: wk.sequence == 0):
|
if workorder.production_id.workorder_ids.filtered(lambda wk: wk.sequence == 0):
|
||||||
break
|
continue
|
||||||
# ===== 对所有按序号排序的非[进行中、完成、返工、取消]状态的工单,除了第一条之外的工单状态都设置为[等待其他工单] =====
|
# ===== 对所有按序号排序的非[进行中、完成、返工、取消]状态的工单,除了第一条之外的工单状态都设置为[等待其他工单] =====
|
||||||
min_sequence_wk = min(workorder.production_id.workorder_ids.filtered(
|
logging.info(workorder.state)
|
||||||
lambda wk: wk.state not in ['done', 'rework', 'cancel']),
|
work_ids = workorder.production_id.workorder_ids.filtered(
|
||||||
key=lambda wk: wk.sequence)
|
lambda wk: wk.state not in ['done', 'rework', 'cancel'])
|
||||||
if workorder.state in ['done', 'rework', 'cancel', 'progress']:
|
if not work_ids:
|
||||||
|
continue
|
||||||
|
min_sequence_wk = min(work_ids, key=lambda wk: wk.sequence)
|
||||||
|
if workorder.state in ['done', 'rework', 'cancel', 'progress', 'to be detected']:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
if workorder != min_sequence_wk:
|
if workorder != min_sequence_wk:
|
||||||
@@ -1065,7 +1071,9 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
# ================= 如果制造订单刀具状态为[无效刀、缺刀] 或者 制造订单状态为[返工]==========================
|
# ================= 如果制造订单刀具状态为[无效刀、缺刀] 或者 制造订单状态为[返工]==========================
|
||||||
if (workorder.production_id.tool_state in ['1', '2'] or workorder.production_id.state == 'rework'
|
if (workorder.production_id.tool_state in ['1', '2'] or workorder.production_id.state == 'rework'
|
||||||
or workorder.production_id.schedule_state != '已排'
|
or workorder.production_id.schedule_state != '已排'
|
||||||
or workorder.production_id.reservation_state != 'assigned'):
|
or workorder.production_id.reservation_state != 'assigned'
|
||||||
|
or workorder.production_id.workorder_ids.filtered(
|
||||||
|
lambda wk: wk.sequence == workorder.sequence - 1).test_results in ['报废', '返工']):
|
||||||
if workorder.state != 'waiting':
|
if workorder.state != 'waiting':
|
||||||
workorder.state = 'waiting'
|
workorder.state = 'waiting'
|
||||||
continue
|
continue
|
||||||
@@ -1265,11 +1273,11 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
def button_finish(self):
|
def button_finish(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
if record.routing_type == '装夹预调':
|
if record.routing_type == '装夹预调':
|
||||||
if not record.rfid_code and record.is_rework is False:
|
# if not record.rfid_code and record.is_rework is False:
|
||||||
raise UserError("请扫RFID码进行绑定")
|
# raise UserError("请扫RFID码进行绑定")
|
||||||
if record.is_rework is False:
|
# if record.is_rework is False:
|
||||||
if not record.material_center_point:
|
# if not record.material_center_point:
|
||||||
raise UserError("坯料中心点为空,请检查")
|
# raise UserError("坯料中心点为空,请检查")
|
||||||
# if record.X_deviation_angle <= 0:
|
# if record.X_deviation_angle <= 0:
|
||||||
# raise UserError("X偏差角度小于等于0,请检查!本次计算的X偏差角度为:%s" % record.X_deviation_angle)
|
# raise UserError("X偏差角度小于等于0,请检查!本次计算的X偏差角度为:%s" % record.X_deviation_angle)
|
||||||
record.process_state = '待加工'
|
record.process_state = '待加工'
|
||||||
|
|||||||
@@ -312,7 +312,6 @@ class StockRule(models.Model):
|
|||||||
i = 0
|
i = 0
|
||||||
if production_item.product_id.categ_id.type == '成品':
|
if production_item.product_id.categ_id.type == '成品':
|
||||||
# 根据加工面板的面数及成品工序模板生成工序设计
|
# 根据加工面板的面数及成品工序模板生成工序设计
|
||||||
|
|
||||||
for k in (production_item.product_id.model_processing_panel.split(',')):
|
for k in (production_item.product_id.model_processing_panel.split(',')):
|
||||||
if production_item.production_type == '自动化产线加工':
|
if production_item.production_type == '自动化产线加工':
|
||||||
product_routing_workcenter = self.env['sf.product.model.type.routing.sort'].search(
|
product_routing_workcenter = self.env['sf.product.model.type.routing.sort'].search(
|
||||||
|
|||||||
@@ -29,26 +29,26 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
|
|||||||
if ret['manufacturing_type'] in ('scrap', 'invalid_tool_rework'):
|
if ret['manufacturing_type'] in ('scrap', 'invalid_tool_rework'):
|
||||||
domain += [('state', 'not in', ['done', 'scrap', 'cancel'])]
|
domain += [('state', 'not in', ['done', 'scrap', 'cancel'])]
|
||||||
else:
|
else:
|
||||||
domain += [('state', '=', 'confirmed')]
|
domain += [('state', 'in', ['confirmed', 'pending_cam'])]
|
||||||
productions = request.env['mrp.production'].with_user(
|
productions = request.env['mrp.production'].with_user(
|
||||||
request.env.ref("base.user_admin")).search(domain)
|
request.env.ref("base.user_admin")).search(domain)
|
||||||
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):
|
||||||
files_r = os.listdir(program_path_tmp_r)
|
# files_r = os.listdir(program_path_tmp_r)
|
||||||
if files_r:
|
# if files_r:
|
||||||
for file_name in files_r:
|
# for file_name in files_r:
|
||||||
file_path = os.path.join(program_path_tmp_r, file_name)
|
# file_path = os.path.join(program_path_tmp_r, file_name)
|
||||||
os.remove(file_path)
|
# os.remove(file_path)
|
||||||
download_state = request.env['sf.cnc.processing'].with_user(
|
# download_state = request.env['sf.cnc.processing'].with_user(
|
||||||
request.env.ref("base.user_admin")).download_file_tmp(
|
# request.env.ref("base.user_admin")).download_file_tmp(
|
||||||
ret['folder_name'], r)
|
# ret['folder_name'], r)
|
||||||
if download_state is False:
|
# if download_state is False:
|
||||||
res['status'] = -2
|
# res['status'] = -2
|
||||||
res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no'])
|
# res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no'])
|
||||||
return json.JSONEncoder().encode(res)
|
# return json.JSONEncoder().encode(res)
|
||||||
for production in productions:
|
for production in productions:
|
||||||
for panel in ret['processing_panel'].split(','):
|
for panel in ret['processing_panel'].split(','):
|
||||||
# 查询状态为进行中且工序类型为CNC加工的工单
|
# 查询状态为进行中且工序类型为CNC加工的工单
|
||||||
@@ -65,29 +65,29 @@ class Sf_Mrs_Connect(http.Controller, MultiInheritController):
|
|||||||
cnc_workorder_has.write(
|
cnc_workorder_has.write(
|
||||||
{'cnc_ids': cnc_workorder_has.cnc_ids.sudo()._json_cnc_processing(panel, ret),
|
{'cnc_ids': cnc_workorder_has.cnc_ids.sudo()._json_cnc_processing(panel, ret),
|
||||||
'cmm_ids': cnc_workorder_has.cmm_ids.sudo()._json_cmm_program(panel, ret)})
|
'cmm_ids': cnc_workorder_has.cmm_ids.sudo()._json_cmm_program(panel, ret)})
|
||||||
for panel in ret['processing_panel'].split(','):
|
# for panel in ret['processing_panel'].split(','):
|
||||||
# 查询状态为进行中且工序类型为CNC加工的工单
|
# # 查询状态为进行中且工序类型为CNC加工的工单
|
||||||
cnc_workorder = productions.workorder_ids.filtered(
|
# cnc_workorder = productions.workorder_ids.filtered(
|
||||||
lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', 'rework'
|
# lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', 'rework'
|
||||||
'cancel'] and ac.processing_panel == panel)
|
# 'cancel'] and ac.processing_panel == panel)
|
||||||
if cnc_workorder:
|
# if cnc_workorder:
|
||||||
# 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)
|
||||||
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]
|
||||||
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_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())})
|
# cnc_workorder.write({'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())})
|
||||||
pre_workorder = productions.workorder_ids.filtered(
|
# pre_workorder = productions.workorder_ids.filtered(
|
||||||
lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', 'rework'
|
# lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', 'rework'
|
||||||
'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())})
|
||||||
productions.write({'programming_state': '已编程', 'work_state': '已编程'})
|
productions.write({'programming_state': '已编程', 'work_state': '已编程'})
|
||||||
logging.info('已更新制造订单编程状态:%s' % productions.ids)
|
logging.info('已更新制造订单编程状态:%s' % productions.ids)
|
||||||
res.update({
|
res.update({
|
||||||
|
|||||||
Reference in New Issue
Block a user