原来的代码试图访问 test_order_id 字段,但 TestWorkOrder 模型中没有这个字段。正确的字段名是:

order_id - 关联的订单ID
batch_id - 工单批次ID
main
risingLee 2026-01-09 01:56:22 +08:00
parent d9fd368d55
commit 0065a1aea4
1 changed files with 8 additions and 6 deletions

View File

@ -201,14 +201,16 @@ class Test_work_orderService:
if len(work_orders) != len(work_order_ids):
raise ServiceException(message="部分工单不存在")
# 2. 验证工单是否属于同一订单(同一客户)
order_ids = list(set([wo.test_order_id for wo in work_orders]))
if len(order_ids) > 1:
raise ServiceException(message="选中的工单必须属于同一订单")
# 2. 验证工单是否属于同一批次
batch_ids = list(set([wo.batch_id for wo in work_orders if wo.batch_id]))
if len(batch_ids) > 1:
raise ServiceException(message="选中的工单必须属于同一批次")
# 3. 检查工单是否已关联订单
# 注意:这里允许已关联订单的工单重新生成,但会给出警告
# 实际业务中可能需要更严格的验证
already_linked = [wo for wo in work_orders if wo.order_id is not None]
if already_linked:
# 给出警告但允许继续(根据业务需求可以改为抛出异常)
pass
# 4. 创建新订单
new_order = Test_orderModel(