fix(lastleg): reconfirm received bookings after releasing all own cargo

This commit is contained in:
2026-10-18 19:53:35 +08:00
parent 2c330bf9df
commit 45fbd6eff8
7 changed files with 139 additions and 13 deletions
@@ -309,8 +309,11 @@ export async function verifyDispatchRepair(context, fixtures, { execute = false
const displayed = current.items?.find(row => id(row.warehousePalletId) === id(sample.palletId))
const expectedDisplay = sample.displayKind === 'ORDINARY' ? normal.key : external.key
must(displayed?.inboundCode === expectedDisplay && displayed.palletNo && id(current.overseasWarehouseId) === id(f.warehouseId), 'Displayed source does not match its independently produced ordinary/external origin')
const balances = (await pages(`${BASE}/inventory/balances?${new URLSearchParams({ customerId: f.customerId, overseasWarehouseId: f.warehouseId })}`))
.filter(row => id(row.customerId) === id(f.customerId) && id(row.overseasWarehouseId) === id(f.warehouseId))
// The list groups equal SKUs across inbounds; constrain each real source before taking representative balance IDs.
const sourceBalances = []
for (const inboundCode of [normal.key, external.key]) sourceBalances.push(...await pages(`${BASE}/inventory/balances?${new URLSearchParams({ customerId: f.customerId, overseasWarehouseId: f.warehouseId, inboundCode })}`))
const balances = [...new Map(sourceBalances.filter(row => id(row.customerId) === id(f.customerId)
&& id(row.overseasWarehouseId) === id(f.warehouseId)).map(row => [id(row.id), row])).values()]
const quantities = new Map(), positions = []
for (const balance of balances) {
const rows = await call('GET', `${BASE}/inventory/balances/${encodeURIComponent(id(balance.id))}/positions?${new URLSearchParams({ customerId: f.customerId, palletNo: displayed.palletNo })}`)