From 9cf2bac9c6445d6c6a462f019b5b243d77b74d8f Mon Sep 17 00:00:00 2001 From: guanhuan Date: Mon, 9 Jun 2025 17:39:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=94=E5=B7=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_workorder.py | 38 ++++++++++++++---------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 4cc1dae6..c5046722 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -227,22 +227,30 @@ class ResMrpWorkOrder(models.Model): # finish_move.move_dest_ids.move_line_ids.reserved_uom_qty = 0 else: next_workorder = sorted_workorders[position + 1] - next_state = next_workorder.state - if next_state not in ['pending', 'waiting', 'ready']: - raise UserError('下工序已经开始,无法回退') - if next_workorder.is_subcontract: - next_workorder.picking_ids.write({'state': 'waiting'}) - next_workorder.state = 'pending' - self.time_ids.date_end = None - cur_workorder.state = 'progress' - cur_workorder.production_id.state = 'progress' - quality_check = self.env['quality.check'].search( - [('workorder_id', '=', self.id)]) - for check_order in quality_check: - if check_order.point_id.is_inspect: - check_order.quality_state = 'waiting' + # 持续获取下一个工单,直到找到一个不是返工的工单 + while next_workorder and next_workorder.state == 'rework': + position += 1 + if position + 1 < len(sorted_workorders): + next_workorder = sorted_workorders[position + 1] else: - check_order.quality_state = 'none' + next_workorder = None + if next_workorder: + next_state = next_workorder.state + if next_state not in ['pending', 'waiting', 'ready']: + raise UserError('下工序已经开始,无法回退') + if next_workorder.is_subcontract: + next_workorder.picking_ids.write({'state': 'waiting'}) + next_workorder.state = 'pending' + self.time_ids.date_end = None + cur_workorder.state = 'progress' + cur_workorder.production_id.state = 'progress' + quality_check = self.env['quality.check'].search( + [('workorder_id', '=', self.id)]) + for check_order in quality_check: + if check_order.point_id.is_inspect: + check_order.quality_state = 'waiting' + else: + check_order.quality_state = 'none' def _compute_working_users(self): super()._compute_working_users()