工单状态方法优化
This commit is contained in:
@@ -145,7 +145,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
tag_type = fields.Selection([("重新加工", "重新加工")], string="标签", tracking=True)
|
||||
|
||||
def _compute_default_construction_period_status(self):
|
||||
need_list=['pending', 'waiting', 'ready', 'progress', 'to be detected','done']
|
||||
need_list = ['pending', 'waiting', 'ready', 'progress', 'to be detected', 'done']
|
||||
try:
|
||||
if self.state not in need_list:
|
||||
return False
|
||||
@@ -154,9 +154,9 @@ class ResMrpWorkOrder(models.Model):
|
||||
hours = self.get_hours_diff()
|
||||
if hours >= 12:
|
||||
return '正常'
|
||||
elif hours > 0 and hours < 12 and self.state!='done':
|
||||
elif hours > 0 and hours < 12 and self.state != 'done':
|
||||
return '预警'
|
||||
elif hours > 0 and hours < 12 and self.state=='done':
|
||||
elif hours > 0 and hours < 12 and self.state == 'done':
|
||||
return '正常'
|
||||
else:
|
||||
return '已逾期'
|
||||
@@ -168,7 +168,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
def _compute_construction_period_status(self):
|
||||
for worker in self:
|
||||
construction_period_status = worker._compute_default_construction_period_status()
|
||||
if construction_period_status and worker.construction_period_status!=construction_period_status:
|
||||
if construction_period_status and worker.construction_period_status != construction_period_status:
|
||||
worker.construction_period_status = construction_period_status
|
||||
|
||||
construction_period_status = fields.Selection([('正常', '正常'), ('预警', '预警'), ('已逾期', '已逾期')],
|
||||
@@ -199,14 +199,17 @@ class ResMrpWorkOrder(models.Model):
|
||||
func(records)
|
||||
# 增加页码
|
||||
page_number += 1
|
||||
def run_compute_construction_period_status(self,records):
|
||||
|
||||
def run_compute_construction_period_status(self, records):
|
||||
records._compute_construction_period_status()
|
||||
|
||||
def _corn_update_construction_period_status(self):
|
||||
need_list=['pending', 'waiting', 'ready', 'progress', 'to be detected']
|
||||
need_list = ['pending', 'waiting', 'ready', 'progress', 'to be detected']
|
||||
# need_list = [
|
||||
# 'progress',
|
||||
# 'to be detected']
|
||||
self.get_page_all_records('mrp.workorder',self.run_compute_construction_period_status,[('state', 'in', need_list)],100)
|
||||
self.get_page_all_records('mrp.workorder', self.run_compute_construction_period_status,
|
||||
[('state', 'in', need_list)], 100)
|
||||
|
||||
def get_hours_diff(self):
|
||||
# 获取当前日期和时间
|
||||
@@ -1001,7 +1004,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:
|
||||
@@ -1042,147 +1045,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):
|
||||
|
||||
Reference in New Issue
Block a user