Merge branch 'feature/返工优化' of https://e.coding.net/jikimo-hn/jikimo_sfs/jikimo_sf into feature/优化外协采购和出入库单(工艺退回调整)

This commit is contained in:
jinling.yang
2024-11-21 10:44:51 +08:00
4 changed files with 246 additions and 258 deletions

View File

@@ -869,7 +869,8 @@ class MrpProduction(models.Model):
work_id.sequence = order_id.sequence + 1
break
# 对该工单之后的工单工序进行加一
work_order_ids = rec.workorder_ids.filtered(lambda item: item.sequence >= work_id.sequence)
work_order_ids = rec.workorder_ids.filtered(
lambda item: item.sequence >= work_id.sequence and item.id != work_id.id)
for work in work_order_ids:
work.sequence = work.sequence + 1
@@ -1139,6 +1140,7 @@ class MrpProduction(models.Model):
'target': 'new',
'context': {
'default_production_id': self.id,
'default_workorder_ids': self.workorder_ids.filtered(lambda wk: wk.state == 'done').ids,
'default_reprogramming_num': cloud_programming['reprogramming_num'],
'default_programming_state': cloud_programming['programming_state'],
'default_is_reprogramming': True if cloud_programming['programming_state'] in ['已下发'] else False

View File

@@ -1005,7 +1005,7 @@ class ResMrpWorkOrder(models.Model):
return workorders_values_str
@api.depends('production_availability', 'blocked_by_workorder_ids', 'blocked_by_workorder_ids.state',
'production_id.tool_state', 'production_id.schedule_state')
'production_id.tool_state', 'production_id.schedule_state', 'sequence')
def _compute_state(self):
# super()._compute_state()
for workorder in self:
@@ -1046,147 +1046,107 @@ class ResMrpWorkOrder(models.Model):
workorder.state = 'ready'
elif workorder.production_id.reservation_state != 'assigned' and workorder.state == 'ready':
workorder.state = 'waiting'
re_work = self.env['mrp.workorder'].search([('production_id', '=', workorder.production_id.id),
('processing_panel', '=', workorder.processing_panel),
('is_rework', '=', True), ('state', 'in', ['done', 'rework'])])
cnc_workorder = self.env['mrp.workorder'].search(
[('production_id', '=', workorder.production_id.id),
('processing_panel', '=', workorder.processing_panel),
('routing_type', '=', 'CNC加工'), ('state', 'in', ['done', 'rework']),
('test_results', '=', '返工')])
cnc_workorder_pending = self.env['mrp.workorder'].search(
[('production_id', '=', workorder.production_id.id),
('processing_panel', '=', workorder.processing_panel),
('routing_type', '=', 'CNC加工'), ('state', 'in', ['pending'])])
unclamp_workorder = self.env['mrp.workorder'].search(
[('production_id', '=', workorder.production_id.id),
('sequence', '=', workorder.sequence - 1),
('state', 'in', ['done'])])
if workorder.state not in ['cancel', 'progress', 'rework']:
if workorder.production_id.state == 'rework':
if workorder.routing_type == '装夹预调' and workorder.state not in ['done', 'rework',
'cancel']:
# # 有返工工单
# if re_work:
# 新工单
if workorder.is_rework is False:
if workorder.production_id.programming_state == '已编程' and workorder.production_id.is_rework is False:
if re_work or cnc_workorder:
workorder.state = 'ready'
else:
if workorder.production_id.is_rework is True:
if re_work or cnc_workorder:
workorder.state = 'waiting'
elif workorder.routing_type == 'CNC加工' and workorder.state not in ['done', 'rework', 'cancel']:
pre_workorder = self.env['mrp.workorder'].search(
[('production_id', '=', workorder.production_id.id),
('processing_panel', '=', workorder.processing_panel),
('routing_type', '=', '装夹预调'), ('state', '=', 'done')])
if pre_workorder:
if re_work:
workorder.state = 'waiting'
elif workorder.routing_type == '解除装夹' and workorder.state not in ['done', 'rework', 'cancel']:
if cnc_workorder:
if not cnc_workorder_pending or unclamp_workorder.test_results == '报废':
workorder.state = 'waiting'
# else:
# if workorder.production_id.is_rework is True:
# workorder.state = 'waiting'
elif workorder.production_id.state == 'progress':
if workorder.routing_type == '装夹预调' and workorder.production_id.programming_state == '已编程' and \
workorder.is_rework is False and workorder.state not in [
'done', 'rework',
'cancel']:
if workorder.production_id.is_rework is False:
if re_work or cnc_workorder or unclamp_workorder:
workorder.state = 'ready'
# if (re_work or cnc_workorder) and workorder.production_id.is_rework is False:
# workorder.state = 'ready'
if workorder.routing_type == '表面工艺' and workorder.state not in ['done', 'progress']:
if unclamp_workorder:
if workorder.is_subcontract is False:
workorder.state = 'ready'
else:
production_programming = self.env['mrp.production'].search(
[('origin', '=', self.production_id.origin)], order='name asc')
production_no_remanufacture = production_programming.filtered(
lambda a: a.is_remanufacture is False)
production_list = [production.name for production in production_programming]
purchase_orders = self.env['purchase.order'].search(
[('origin', 'ilike', ','.join(production_list))])
for line in purchase_orders.order_line:
if line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id and line.product_qty == len(
production_no_remanufacture):
if purchase_orders.state == 'purchase':
workorder.state = 'ready'
else:
workorder.state = 'waiting'
elif workorder.production_id.state == 'scrap':
if workorder.routing_type == '解除装夹' and unclamp_workorder.test_results == '报废':
workorder.state = 'waiting'
# if workorder.routing_type == '装夹预调' and workorder.state in ['waiting', 'ready', 'pending']:
# workorder_ids = workorder.production_id.workorder_ids
# work_bo = True
# for wo in workorder_ids.filtered(lambda a: a.routing_type == '装夹预调' and a.state == 'rework'):
# if not workorder_ids.filtered(
# lambda a: (a.routing_type == '装夹预调' and a.state not in ['rework', 'cancel']
# and a.processing_panel == wo.processing_panel)):
# work_bo = False
# break
# if (workorder.production_id.programming_state == '已编程' and work_bo
# and not workorder_ids.filtered(lambda a: a.sequence == 0)):
# # 当工单对应制造订单的功能刀具状态为 【无效刀】时,先对的第一个装夹预调工单状态设置为 【等待组件】
# if workorder.production_id.tool_state in ['1', '2']:
# if workorder.state in ['ready']:
# workorder.state = 'waiting'
# continue
# elif workorder.state in ['waiting']:
# continue
# elif workorder.state == 'pending' and workorder == self.search(
# [('production_id', '=', workorder.production_id.id),
# ('routing_type', '=', '装夹预调'),
# ('state', 'not in', ['rework', 'done', 'cancel'])],
# limit=1,
# order="sequence"):
# workorder.state = 'waiting'
# continue
# elif workorder.production_id.tool_state in ['0']:
# if workorder_ids.filtered(lambda a: a.state == 'rework'):
# if not workorder_ids.filtered(
# lambda a: (a.routing_type not in ['装夹预调'] and
# a.state not in ['pending', 'done', 'rework', 'cancel'])):
# # 查询工序最小的非完工、非返工的装夹预调工单
# work_id = self.search(
# [('production_id', '=', workorder.production_id.id),
# ('state', 'not in', ['rework', 'done', 'cancel'])],
# limit=1,
# order="sequence")
# if work_id.routing_type == '装夹预调':
# if workorder == work_id:
# if workorder.production_id.reservation_state == 'assigned':
# workorder.state = 'ready'
# elif workorder.production_id.reservation_state != 'assigned':
# workorder.state = 'waiting'
# continue
# elif (workorder.name == '装夹预调' and
# workorder.state not in ['rework', 'done', 'cancel']):
# if workorder.state != 'pending':
# workorder.state = 'pending'
# if workorder.production_id.tool_state in ['1', '2'] and workorder.state == 'ready':
# workorder.state = 'waiting'
# continue
# if (workorder.production_id.tool_state in ['1', '2']
# and not workorder.production_id.workorder_ids.filtered(lambda a: a.sequence == 0)
# and workorder.production_id.programming_state == '编程中' and workorder.name == '装夹预调'):
# if workorder.state == 'pending' and workorder == self.search(
# [('production_id', '=', workorder.production_id.id),
# ('routing_type', '=', '装夹预调'),
# ('state', 'not in', ['rework', 'done', 'cancel'])],
# limit=1,
# order="sequence"):
# workorder.state = 'waiting'
# continue
for workorder in self:
# 如果工单的工序没有进行排序则跳出循环
if workorder.production_id.workorder_ids.filtered(lambda wk: wk.sequence == 0):
break
# ===== 对所有按序号排序的非[进行中、完成、返工、取消]状态的工单,除了第一条之外的工单状态都设置为[等待其他工单] =====
min_sequence_wk = min(workorder.production_id.workorder_ids.filtered(
lambda wk: wk.state not in ['done', 'rework', 'cancel']),
key=lambda wk: wk.sequence)
if workorder.state in ['done', 'rework', 'cancel', 'progress']:
continue
else:
if workorder != min_sequence_wk:
if workorder.state != 'pending':
workorder.state = 'pending'
continue
# ================= 如果制造订单刀具状态为[无效刀、缺刀] 或者 制造订单状态为[返工]==========================
if workorder.production_id.tool_state in ['1', '2'] or workorder.production_id.state == 'rework':
workorder.state = 'waiting'
continue
if workorder.production_id.programming_state == '已编程':
workorder.state = 'ready'
else:
workorder.state = 'waiting'
# re_work = self.env['mrp.workorder'].search([('production_id', '=', workorder.production_id.id),
# ('processing_panel', '=', workorder.processing_panel),
# ('is_rework', '=', True), ('state', 'in', ['done', 'rework'])])
# cnc_workorder = self.env['mrp.workorder'].search(
# [('production_id', '=', workorder.production_id.id),
# ('processing_panel', '=', workorder.processing_panel),
# ('routing_type', '=', 'CNC加工'), ('state', 'in', ['done', 'rework']),
# ('test_results', '=', '返工')])
# cnc_workorder_pending = self.env['mrp.workorder'].search(
# [('production_id', '=', workorder.production_id.id),
# ('processing_panel', '=', workorder.processing_panel),
# ('routing_type', '=', 'CNC加工'), ('state', 'in', ['pending'])])
# unclamp_workorder = self.env['mrp.workorder'].search(
# [('production_id', '=', workorder.production_id.id),
# ('sequence', '=', workorder.sequence - 1),
# ('state', 'in', ['done'])])
# if workorder.state not in ['cancel', 'progress', 'rework']:
# if workorder.production_id.state == 'rework':
# if workorder.routing_type == '装夹预调':
# # # 有返工工单
# # if re_work:
# # 新工单
# if workorder.is_rework is False:
# if (workorder.production_id.programming_state == '已编程'
# and workorder.production_id.is_rework is False):
# if re_work or cnc_workorder:
# workorder.state = 'ready'
# else:
# if workorder.production_id.is_rework is True:
# if re_work or cnc_workorder:
# workorder.state = 'waiting'
#
# elif workorder.routing_type == 'CNC加工':
# pre_workorder = self.env['mrp.workorder'].search(
# [('production_id', '=', workorder.production_id.id),
# ('processing_panel', '=', workorder.processing_panel),
# ('routing_type', '=', '装夹预调'), ('state', '=', 'done')])
# if pre_workorder:
# if re_work:
# workorder.state = 'waiting'
# elif workorder.routing_type == '解除装夹':
# if cnc_workorder:
# if not cnc_workorder_pending or unclamp_workorder.test_results == '报废':
# workorder.state = 'waiting'
# # else:
# # if workorder.production_id.is_rework is True:
# # workorder.state = 'waiting'
# elif workorder.production_id.state == 'progress':
# if (workorder.routing_type == '装夹预调' and workorder.production_id.programming_state == '已编程'
# and workorder.is_rework is False and workorder.state not in ['done', 'rework', 'cancel']):
# if workorder.production_id.is_rework is False:
# if re_work or cnc_workorder or unclamp_workorder:
# workorder.state = 'ready'
# # if (re_work or cnc_workorder) and workorder.production_id.is_rework is False:
# # workorder.state = 'ready'
# if workorder.routing_type == '表面工艺' and workorder.state not in ['done', 'progress']:
# if unclamp_workorder:
# if workorder.is_subcontract is False:
# workorder.state = 'ready'
# else:
# production_programming = self.env['mrp.production'].search(
# [('origin', '=', self.production_id.origin)], order='name asc')
# production_no_remanufacture = production_programming.filtered(
# lambda a: a.is_remanufacture is False)
# production_list = [production.name for production in production_programming]
# purchase_orders = self.env['purchase.order'].search(
# [('origin', 'ilike', ','.join(production_list))])
# for line in purchase_orders.order_line:
# if line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id and line.product_qty == len(
# production_no_remanufacture):
# if purchase_orders.state == 'purchase':
# workorder.state = 'ready'
# else:
# workorder.state = 'waiting'
# elif workorder.production_id.state == 'scrap':
# if workorder.routing_type == '解除装夹' and unclamp_workorder.test_results == '报废':
# workorder.state = 'waiting'
# 重写工单开始按钮方法
def button_start(self):