工单状态方法优化

This commit is contained in:
yuxianghui
2024-11-21 10:43:22 +08:00
parent f8f5286568
commit ded0d06f86

View File

@@ -145,7 +145,7 @@ class ResMrpWorkOrder(models.Model):
tag_type = fields.Selection([("重新加工", "重新加工")], string="标签", tracking=True) tag_type = fields.Selection([("重新加工", "重新加工")], string="标签", tracking=True)
def _compute_default_construction_period_status(self): 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: try:
if self.state not in need_list: if self.state not in need_list:
return False return False
@@ -154,9 +154,9 @@ class ResMrpWorkOrder(models.Model):
hours = self.get_hours_diff() hours = self.get_hours_diff()
if hours >= 12: if hours >= 12:
return '正常' return '正常'
elif hours > 0 and hours < 12 and self.state!='done': elif hours > 0 and hours < 12 and self.state != 'done':
return '预警' return '预警'
elif hours > 0 and hours < 12 and self.state=='done': elif hours > 0 and hours < 12 and self.state == 'done':
return '正常' return '正常'
else: else:
return '已逾期' return '已逾期'
@@ -168,7 +168,7 @@ class ResMrpWorkOrder(models.Model):
def _compute_construction_period_status(self): def _compute_construction_period_status(self):
for worker in self: for worker in self:
construction_period_status = worker._compute_default_construction_period_status() 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 worker.construction_period_status = construction_period_status
construction_period_status = fields.Selection([('正常', '正常'), ('预警', '预警'), ('已逾期', '已逾期')], construction_period_status = fields.Selection([('正常', '正常'), ('预警', '预警'), ('已逾期', '已逾期')],
@@ -199,14 +199,17 @@ class ResMrpWorkOrder(models.Model):
func(records) func(records)
# 增加页码 # 增加页码
page_number += 1 page_number += 1
def run_compute_construction_period_status(self,records):
def run_compute_construction_period_status(self, records):
records._compute_construction_period_status() records._compute_construction_period_status()
def _corn_update_construction_period_status(self): 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 = [ # need_list = [
# 'progress', # 'progress',
# 'to be detected'] # '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): def get_hours_diff(self):
# 获取当前日期和时间 # 获取当前日期和时间
@@ -1001,7 +1004,7 @@ class ResMrpWorkOrder(models.Model):
return workorders_values_str return workorders_values_str
@api.depends('production_availability', 'blocked_by_workorder_ids', 'blocked_by_workorder_ids.state', @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): def _compute_state(self):
# super()._compute_state() # super()._compute_state()
for workorder in self: for workorder in self:
@@ -1042,147 +1045,107 @@ class ResMrpWorkOrder(models.Model):
workorder.state = 'ready' workorder.state = 'ready'
elif workorder.production_id.reservation_state != 'assigned' and workorder.state == 'ready': elif workorder.production_id.reservation_state != 'assigned' and workorder.state == 'ready':
workorder.state = 'waiting' 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']: for workorder in self:
pre_workorder = self.env['mrp.workorder'].search( # 如果工单的工序没有进行排序则跳出循环
[('production_id', '=', workorder.production_id.id), if workorder.production_id.workorder_ids.filtered(lambda wk: wk.sequence == 0):
('processing_panel', '=', workorder.processing_panel), break
('routing_type', '=', '装夹预调'), ('state', '=', 'done')]) # ===== 对所有按序号排序的非[进行中、完成、返工、取消]状态的工单,除了第一条之外的工单状态都设置为[等待其他工单] =====
if pre_workorder: min_sequence_wk = min(workorder.production_id.workorder_ids.filtered(
if re_work: lambda wk: wk.state not in ['done', 'rework', 'cancel']),
workorder.state = 'waiting' key=lambda wk: wk.sequence)
elif workorder.routing_type == '解除装夹' and workorder.state not in ['done', 'rework', 'cancel']: if workorder.state in ['done', 'rework', 'cancel', 'progress']:
if cnc_workorder: continue
if not cnc_workorder_pending or unclamp_workorder.test_results == '报废': else:
workorder.state = 'waiting' if workorder != min_sequence_wk:
# else: if workorder.state != 'pending':
# if workorder.production_id.is_rework is True: workorder.state = 'pending'
# workorder.state = 'waiting' continue
elif workorder.production_id.state == 'progress': # ================= 如果制造订单刀具状态为[无效刀、缺刀] 或者 制造订单状态为[返工]==========================
if workorder.routing_type == '装夹预调' and workorder.production_id.programming_state == '已编程' and \ if workorder.production_id.tool_state in ['1', '2'] or workorder.production_id.state == 'rework':
workorder.is_rework is False and workorder.state not in [ workorder.state = 'waiting'
'done', 'rework', continue
'cancel']: if workorder.production_id.programming_state == '已编程':
if workorder.production_id.is_rework is False: workorder.state = 'ready'
if re_work or cnc_workorder or unclamp_workorder: else:
workorder.state = 'ready' workorder.state = 'waiting'
# if (re_work or cnc_workorder) and workorder.production_id.is_rework is False: # re_work = self.env['mrp.workorder'].search([('production_id', '=', workorder.production_id.id),
# workorder.state = 'ready' # ('processing_panel', '=', workorder.processing_panel),
if workorder.routing_type == '表面工艺' and workorder.state not in ['done', 'progress']: # ('is_rework', '=', True), ('state', 'in', ['done', 'rework'])])
if unclamp_workorder: # cnc_workorder = self.env['mrp.workorder'].search(
if workorder.is_subcontract is False: # [('production_id', '=', workorder.production_id.id),
workorder.state = 'ready' # ('processing_panel', '=', workorder.processing_panel),
else: # ('routing_type', '=', 'CNC加工'), ('state', 'in', ['done', 'rework']),
production_programming = self.env['mrp.production'].search( # ('test_results', '=', '返工')])
[('origin', '=', self.production_id.origin)], order='name asc') # cnc_workorder_pending = self.env['mrp.workorder'].search(
production_no_remanufacture = production_programming.filtered( # [('production_id', '=', workorder.production_id.id),
lambda a: a.is_remanufacture is False) # ('processing_panel', '=', workorder.processing_panel),
production_list = [production.name for production in production_programming] # ('routing_type', '=', 'CNC加工'), ('state', 'in', ['pending'])])
purchase_orders = self.env['purchase.order'].search( # unclamp_workorder = self.env['mrp.workorder'].search(
[('origin', 'ilike', ','.join(production_list))]) # [('production_id', '=', workorder.production_id.id),
for line in purchase_orders.order_line: # ('sequence', '=', workorder.sequence - 1),
if line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id and line.product_qty == len( # ('state', 'in', ['done'])])
production_no_remanufacture): # if workorder.state not in ['cancel', 'progress', 'rework']:
if purchase_orders.state == 'purchase': # if workorder.production_id.state == 'rework':
workorder.state = 'ready' # if workorder.routing_type == '装夹预调':
else: # # # 有返工工单
workorder.state = 'waiting' # # if re_work:
elif workorder.production_id.state == 'scrap': # # 新工单
if workorder.routing_type == '解除装夹' and unclamp_workorder.test_results == '报废': # if workorder.is_rework is False:
workorder.state = 'waiting' # if (workorder.production_id.programming_state == '已编程'
# if workorder.routing_type == '装夹预调' and workorder.state in ['waiting', 'ready', 'pending']: # and workorder.production_id.is_rework is False):
# workorder_ids = workorder.production_id.workorder_ids # if re_work or cnc_workorder:
# work_bo = True # workorder.state = 'ready'
# for wo in workorder_ids.filtered(lambda a: a.routing_type == '装夹预调' and a.state == 'rework'): # else:
# if not workorder_ids.filtered( # if workorder.production_id.is_rework is True:
# lambda a: (a.routing_type == '装夹预调' and a.state not in ['rework', 'cancel'] # if re_work or cnc_workorder:
# and a.processing_panel == wo.processing_panel)): # workorder.state = 'waiting'
# work_bo = False #
# break # elif workorder.routing_type == 'CNC加工':
# if (workorder.production_id.programming_state == '已编程' and work_bo # pre_workorder = self.env['mrp.workorder'].search(
# and not workorder_ids.filtered(lambda a: a.sequence == 0)): # [('production_id', '=', workorder.production_id.id),
# # 当工单对应制造订单的功能刀具状态为 【无效刀】时,先对的第一个装夹预调工单状态设置为 【等待组件】 # ('processing_panel', '=', workorder.processing_panel),
# if workorder.production_id.tool_state in ['1', '2']: # ('routing_type', '=', '装夹预调'), ('state', '=', 'done')])
# if workorder.state in ['ready']: # if pre_workorder:
# workorder.state = 'waiting' # if re_work:
# continue # workorder.state = 'waiting'
# elif workorder.state in ['waiting']: # elif workorder.routing_type == '解除装夹':
# continue # if cnc_workorder:
# elif workorder.state == 'pending' and workorder == self.search( # if not cnc_workorder_pending or unclamp_workorder.test_results == '报废':
# [('production_id', '=', workorder.production_id.id), # workorder.state = 'waiting'
# ('routing_type', '=', '装夹预调'), # # else:
# ('state', 'not in', ['rework', 'done', 'cancel'])], # # if workorder.production_id.is_rework is True:
# limit=1, # # workorder.state = 'waiting'
# order="sequence"): # elif workorder.production_id.state == 'progress':
# workorder.state = 'waiting' # if (workorder.routing_type == '装夹预调' and workorder.production_id.programming_state == '已编程'
# continue # and workorder.is_rework is False and workorder.state not in ['done', 'rework', 'cancel']):
# elif workorder.production_id.tool_state in ['0']: # if workorder.production_id.is_rework is False:
# if workorder_ids.filtered(lambda a: a.state == 'rework'): # if re_work or cnc_workorder or unclamp_workorder:
# if not workorder_ids.filtered( # workorder.state = 'ready'
# lambda a: (a.routing_type not in ['装夹预调'] and # # if (re_work or cnc_workorder) and workorder.production_id.is_rework is False:
# a.state not in ['pending', 'done', 'rework', 'cancel'])): # # workorder.state = 'ready'
# # 查询工序最小的非完工、非返工的装夹预调工单 # if workorder.routing_type == '表面工艺' and workorder.state not in ['done', 'progress']:
# work_id = self.search( # if unclamp_workorder:
# [('production_id', '=', workorder.production_id.id), # if workorder.is_subcontract is False:
# ('state', 'not in', ['rework', 'done', 'cancel'])], # workorder.state = 'ready'
# limit=1, # else:
# order="sequence") # production_programming = self.env['mrp.production'].search(
# if work_id.routing_type == '装夹预调': # [('origin', '=', self.production_id.origin)], order='name asc')
# if workorder == work_id: # production_no_remanufacture = production_programming.filtered(
# if workorder.production_id.reservation_state == 'assigned': # lambda a: a.is_remanufacture is False)
# workorder.state = 'ready' # production_list = [production.name for production in production_programming]
# elif workorder.production_id.reservation_state != 'assigned': # purchase_orders = self.env['purchase.order'].search(
# workorder.state = 'waiting' # [('origin', 'ilike', ','.join(production_list))])
# continue # for line in purchase_orders.order_line:
# elif (workorder.name == '装夹预调' and # if line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id and line.product_qty == len(
# workorder.state not in ['rework', 'done', 'cancel']): # production_no_remanufacture):
# if workorder.state != 'pending': # if purchase_orders.state == 'purchase':
# workorder.state = 'pending' # workorder.state = 'ready'
# if workorder.production_id.tool_state in ['1', '2'] and workorder.state == 'ready': # else:
# workorder.state = 'waiting' # workorder.state = 'waiting'
# continue # elif workorder.production_id.state == 'scrap':
# if (workorder.production_id.tool_state in ['1', '2'] # if workorder.routing_type == '解除装夹' and unclamp_workorder.test_results == '报废':
# and not workorder.production_id.workorder_ids.filtered(lambda a: a.sequence == 0) # workorder.state = 'waiting'
# 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
# 重写工单开始按钮方法 # 重写工单开始按钮方法
def button_start(self): def button_start(self):