diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index b8ea6eec..ea2923bd 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -1533,7 +1533,7 @@ class ResMrpWorkOrder(models.Model): # workorder.rfid_code_old = rfid_code # workorder.rfid_code = False logging.info('workorder.rfid_code:%s' % workorder.rfid_code) - # if is_production_id is True and record.routing_type in ['解除装夹', '表面工艺', '切割']: + if is_production_id is True: logging.info('product_qty:%s' % record.production_id.product_qty) for move_raw_id in record.production_id.move_raw_ids: @@ -1548,6 +1548,17 @@ class ResMrpWorkOrder(models.Model): # if raw_move: # raw_move.write({'state': 'done'}) if record.production_id.state != 'rework': + # 如果工单包含了外协工序,需要预留数量 + if self.move_raw_ids.move_orig_ids.subcontract_workorder_id: + location_id = self.move_raw_ids.location_id + quant = self.move_raw_ids.lot_ids.quant_ids.filtered(lambda q: q.location_id.id == location_id.id) + if quant.reserved_quantity == 0: + self.env['stock.quant']._update_reserved_quantity( + self.move_raw_ids.product_id, + location_id, + quant.quantity, + lot_id=quant.lot_id, + ) record.production_id.button_mark_done1() # record.production_id.state = 'done' diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index 051f0507..1f1e45b6 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -690,7 +690,8 @@ class StockPicking(models.Model): # 如果当前工单是是制造订单的最后一个工艺外协工单 if workorder == next((workorder for workorder in reversed(sorted_workorders) if workorder.is_subcontract), None): - move_dest_id = item.move_raw_ids[0].id + if item.move_raw_ids: + move_dest_id = item.move_raw_ids[0].id else: # 从sorted_workorders中找到上一工单的move if len(sorted_workorders) > 1: @@ -726,6 +727,7 @@ class StockPicking(models.Model): moves_out._action_confirm() moves_out._assign_picking_post_process(new=new_picking) + @api.depends('move_type', 'immediate_transfer', 'move_ids.state', 'move_ids.picking_id') def _compute_state(self): super(StockPicking, self)._compute_state() @@ -849,6 +851,7 @@ class ReStockMove(models.Model): # 'route_ids': False if not route else [(4, route.id)], 'date_deadline': datetime.now(), 'picking_type_id': picking_type_id, + # 'is_subcontract': True, } return move_values @@ -1118,6 +1121,13 @@ class ReStockMove(models.Model): if self.state != 'assigned': self.state = 'assigned' return self.action_show_details() + + def _prepare_move_line_vals(self, quantity=None, reserved_quant=None): + res = super(ReStockMove, self)._prepare_move_line_vals(quantity, reserved_quant) + if self.subcontract_workorder_id: + if self.subcontract_workorder_id.production_id.move_raw_ids.move_line_ids: + res['lot_id'] = self.subcontract_workorder_id.production_id.move_raw_ids.move_line_ids[0].lot_id.id + return res class ReStockQuant(models.Model): diff --git a/sf_message/models/sf_message_workorder.py b/sf_message/models/sf_message_workorder.py index 42b03139..5b73565e 100644 --- a/sf_message/models/sf_message_workorder.py +++ b/sf_message/models/sf_message_workorder.py @@ -191,7 +191,8 @@ class SFMessageWork(models.Model): def write(self, vals): res = super(SFMessageWork, self).write(vals) - if ('leave_id' in vals and vals['leave_id'] is False or 'date_planned_start' in vals and vals['date_planned_start'] is False) \ - and self.schedule_state != '未排': - self.add_queue('计划数据异常跟踪') + for record in self: + if ('leave_id' in vals and vals['leave_id'] is False or 'date_planned_start' in vals and vals['date_planned_start'] is False) \ + and record.schedule_state != '未排': + record.add_queue('计划数据异常跟踪') return res