diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 65f85048..cb3c9ebb 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -910,39 +910,40 @@ class ResMrpWorkOrder(models.Model): # if workorder.state not in ['cancel', 'rework']: # workorder.state = 'rework' if workorder.routing_type == '装夹预调' and workorder.state in ['waiting', 'ready', 'pending']: - # 当工单对应制造订单的功能刀具状态为 【无效刀】时,先对的第一个装夹预调工单状态设置为 【等待组件】 - 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.production_id.workorder_ids.filtered(lambda a: a.state == 'rework'): - if not workorder.production_id.workorder_ids.filtered( - lambda a: (a.routing_type not in ['装夹预调'] and - a.state not in ['pending', 'done', 'rework', 'cancel'])): - # 查询工序最小的非完工、非返工的装夹预调工单 - work_id = self.search( + if workorder.production_id.programming_state == '已编程': + # 当工单对应制造订单的功能刀具状态为 【无效刀】时,先对的第一个装夹预调工单状态设置为 【等待组件】 + 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") - 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 + order="sequence"): + workorder.state = 'waiting' + continue + elif workorder.production_id.tool_state in ['0']: + if workorder.production_id.workorder_ids.filtered(lambda a: a.state == 'rework'): + if not workorder.production_id.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), + ('routing_type', '=', '装夹预调'), + ('state', 'not in', ['rework', 'done', 'cancel'])], + limit=1, + order="sequence") + 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 logging.info('工序:%s' % workorder.sequence) logging.info('工单最终状态:%s' % workorder.state)