|
|
|
@@ -383,24 +383,17 @@ private fun getStockOutIdFromPickOrderLine(pickOrderLineId: Long): Long { |
|
|
|
val unfinishedLine = allStockOutLines.filter { |
|
|
|
val rawStatus = it.status?.trim() |
|
|
|
val status = rawStatus?.lowercase() |
|
|
|
// 兼容多种写法:'COMPLETED'、'completed'、枚举值等 |
|
|
|
val isComplete = status == "completed" || status == StockOutLineStatus.COMPLETE.status.lowercase() |
|
|
|
val isRejected = status == "rejected" || status == StockOutLineStatus.REJECTED.status.lowercase() |
|
|
|
|
|
|
|
// 定义哪些状态算“已结束” |
|
|
|
val isComplete = |
|
|
|
status == "completed" || status == StockOutLineStatus.COMPLETE.status.lowercase() |
|
|
|
val isRejected = |
|
|
|
status == "rejected" || status == StockOutLineStatus.REJECTED.status.lowercase() |
|
|
|
val isPartiallyComplete = |
|
|
|
status == "partially_completed" || status == StockOutLineStatus.PARTIALLY_COMPLETE.status.lowercase() |
|
|
|
|
|
|
|
// 如果「拣货数量 + issue 数量」已经覆盖需求,就把 partially_completed 视为已完成 |
|
|
|
val shouldConsiderPartiallyCompleteAsFinished = if (isPartiallyComplete) { |
|
|
|
if (requiredQty > BigDecimal.ZERO) { |
|
|
|
(totalPickedQty + totalIssueQty) >= requiredQty |
|
|
|
} else { |
|
|
|
false |
|
|
|
} |
|
|
|
} else { |
|
|
|
false |
|
|
|
} |
|
|
|
|
|
|
|
!isComplete && !isRejected && !shouldConsiderPartiallyCompleteAsFinished |
|
|
|
|
|
|
|
// ✅ 现在的规则:这三类状态都算“已结束” |
|
|
|
!(isComplete || isRejected || isPartiallyComplete) |
|
|
|
} |
|
|
|
|
|
|
|
println("Unfinished lines: ${unfinishedLine.size}") |
|
|
|
@@ -687,7 +680,7 @@ private fun getStockOutIdFromPickOrderLine(pickOrderLineId: Long): Long { |
|
|
|
if (pickOrder != null && pickOrder.id != null) { |
|
|
|
// ✅ 修复:使用 repository 查询所有 lines,避免懒加载问题 |
|
|
|
val allLines = pickOrderLineRepository.findAllByPickOrderIdAndDeletedFalse(pickOrder.id!!) |
|
|
|
val allCompleted = allLines.all { it.status == PickOrderLineStatus.COMPLETED } |
|
|
|
val allCompleted = allLines.all { it.status == PickOrderLineStatus.COMPLETED || it.status == PickOrderLineStatus.PARTIALLY_COMPLETE } |
|
|
|
if (allCompleted && allLines.isNotEmpty()) { |
|
|
|
pickOrder.status = PickOrderStatus.COMPLETED |
|
|
|
pickOrderRepository.save(pickOrder) |
|
|
|
@@ -1170,27 +1163,44 @@ open fun newBatchSubmit(request: QrPickBatchSubmitRequest): MessageResponse { |
|
|
|
val stockOutLine = stockOutLines[line.stockOutLineId] |
|
|
|
?: throw IllegalStateException("StockOutLine ${line.stockOutLineId} not found") |
|
|
|
|
|
|
|
// 修复:qty 是 Double?,需要转换为 BigDecimal |
|
|
|
val currentActual = (stockOutLine.qty ?: 0.0).toBigDecimal() |
|
|
|
val targetActual = line.actualPickQty ?: BigDecimal.ZERO |
|
|
|
val required = line.requiredQty ?: BigDecimal.ZERO |
|
|
|
|
|
|
|
println(" Current qty: $currentActual, Target qty: $targetActual, Required: $required") |
|
|
|
|
|
|
|
// 修复:计算增量(前端发送的 actualPickQty 是目标累计值) |
|
|
|
val submitQty = targetActual - currentActual |
|
|
|
|
|
|
|
println(" Submit qty (increment): $submitQty") |
|
|
|
|
|
|
|
// 修复:使用前端发送的状态,而不是重新计算 |
|
|
|
val newStatus = line.stockOutLineStatus ?: if (targetActual >= required) "completed" else "partially_completed" |
|
|
|
|
|
|
|
// 修复:updateStatus 期望增量,所以传入 submitQty |
|
|
|
updateStatus(UpdateStockOutLineStatusRequest( |
|
|
|
id = line.stockOutLineId, |
|
|
|
status = newStatus, |
|
|
|
qty = submitQty.toDouble() |
|
|
|
)) |
|
|
|
val currentActual = (stockOutLine.qty ?: 0.0).toBigDecimal() |
|
|
|
val targetActual = line.actualPickQty ?: BigDecimal.ZERO |
|
|
|
val required = line.requiredQty ?: BigDecimal.ZERO |
|
|
|
|
|
|
|
println(" Current qty: $currentActual, Target qty: $targetActual, Required: $required") |
|
|
|
|
|
|
|
// 计算增量(前端发送的是目标累计值) |
|
|
|
val submitQty = targetActual - currentActual |
|
|
|
|
|
|
|
println(" Submit qty (increment): $submitQty") |
|
|
|
|
|
|
|
// 使用前端发送的状态,否则根据数量自动判断 |
|
|
|
val newStatus = line.stockOutLineStatus |
|
|
|
?: if (targetActual >= required) "completed" else "partially_completed" |
|
|
|
|
|
|
|
if (submitQty <= BigDecimal.ZERO) { |
|
|
|
println(" Submit qty <= 0, only update status for stockOutLineId=${line.stockOutLineId}") |
|
|
|
|
|
|
|
updateStatus( |
|
|
|
UpdateStockOutLineStatusRequest( |
|
|
|
id = line.stockOutLineId, |
|
|
|
status = newStatus, // 例如前端传来的 "completed" |
|
|
|
qty = 0.0 // 不改变现有 qty |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
// 直接跳过后面的库存扣减逻辑 |
|
|
|
return@forEach |
|
|
|
} |
|
|
|
|
|
|
|
// 只有 submitQty > 0 时,才真正增加 qty 并触发库存扣减 |
|
|
|
updateStatus( |
|
|
|
UpdateStockOutLineStatusRequest( |
|
|
|
id = line.stockOutLineId, |
|
|
|
status = newStatus, |
|
|
|
qty = submitQty.toDouble() |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
// Inventory updates - 修复:使用增量数量 |
|
|
|
// ✅ 修复:如果 inventoryLotLineId 为 null,从 stock_out_line 中获取 |
|
|
|
|