fix(overseas): normalize transfer inventory quantities at API boundary

This commit is contained in:
2026-10-04 22:26:36 +08:00
parent 939cc11d7b
commit ea24496b11
7 changed files with 90 additions and 14 deletions
@@ -2,6 +2,7 @@ import { ApiResponseError, http, unwrapApiResponse, type ApiEnvelope } from '@/s
import type { InventoryBalanceDto, InventoryPositionDto } from './inventory'
import { normalizeOverseasPage, type OverseasPagePayload, type OverseasPageResult } from './lastMileOrders'
import type { WarehouseTransferDetailDto } from './warehouseTransfers'
import { normalizeWarehouseTransferQuantity } from './warehouseTransferQuantities'
export interface WarehouseTransferSourceCandidate {
inventoryPositionId: string
@@ -15,7 +16,7 @@ export interface WarehouseTransferSourceCandidate {
canSelect: boolean
blockReason: string
}
type ScopedPosition = InventoryPositionDto & { customerId: string }
type ScopedPosition = Omit<InventoryPositionDto, 'availablePackages'> & { customerId: string; availablePackages: number | string }
export async function listWarehouseTransferSources(customerId: string, transfer: WarehouseTransferDetailDto) {
const sources = new Map((transfer.sourceOrders || []).map(row => [row.inboundOrderId, row]))
if (!customerId || !transfer.operatingWarehouseId || !sources.size || [...sources.values()].some(row => !row.inboundOrderId || !row.inboundCode)) {
@@ -51,10 +52,11 @@ export async function listWarehouseTransferSources(customerId: string, transfer:
continue
}
const sku = balance.skuCode?.trim() || ''
const availablePackages = normalizeWarehouseTransferQuantity(position.availablePackages, '库存位置可分配箱数')
const reason = !position.palletId || !position.palletNo ? '缺少完整托盘业务码,待核查'
: !Number.isSafeInteger(position.availablePackages) || position.availablePackages <= 0 ? '当前无可分配箱数'
: availablePackages <= 0 ? '当前无可分配箱数'
: transfer.needRelabel && (!sku || sku === 'MIXED' || !oldSkus.has(sku)) ? '来源不能证明本票具体旧 SKU,待核查' : ''
candidates.set(position.id, { inventoryPositionId: position.id, palletId: position.palletId || '', inboundCode: source.inboundCode || '', skuCode: sku === 'MIXED' ? '—' : sku || '—', productNameZh: balance.productNameZh || '—', palletNo: position.palletNo || '—', warehouseLocationCode: position.warehouseLocationCode || '—', availablePackages: position.availablePackages, canSelect: !reason, blockReason: reason })
candidates.set(position.id, { inventoryPositionId: position.id, palletId: position.palletId || '', inboundCode: source.inboundCode || '', skuCode: sku === 'MIXED' ? '—' : sku || '—', productNameZh: balance.productNameZh || '—', palletNo: position.palletNo || '—', warehouseLocationCode: position.warehouseLocationCode || '—', availablePackages, canSelect: !reason, blockReason: reason })
}
}
currentPage++