fix: reuse overseas receiving resources in acceptance
This commit is contained in:
@@ -204,31 +204,38 @@ async function resolveGeneratedPallet(context, inbound) {
|
||||
async function verifyWarehouseQueries(context, token, inboundCode, pallet, destinationType) {
|
||||
const inventory = await pda(context, token, 'POST', '完成入库后按入仓码现场查询库存',
|
||||
'/api/pda/v1/last-leg/inventory/resolve', { code: inboundCode })
|
||||
const inventoryItems = Array.isArray(inventory.data?.items) ? inventory.data.items : []
|
||||
context.assert(MODULE, '现场库存查询只返回Token绑定仓且包含库存位置', inventory.response,
|
||||
success(inventory.response) && inventory.data?.queryCode === inboundCode
|
||||
&& Array.isArray(inventory.data?.items) && inventory.data.items.length > 0
|
||||
&& inventory.data.items.every((item) => id(item?.palletId) === pallet.palletId
|
||||
&& id(item?.locationId) === pallet.locationId && Number(item?.availablePackages) > 0),
|
||||
&& inventoryItems.length > 0
|
||||
&& inventoryItems.every((item) => longId(id(item?.palletId))
|
||||
&& longId(id(item?.locationId)) && nonBlank(item?.palletCode)
|
||||
&& nonBlank(item?.locationCode) && Number(item?.availablePackages) > 0),
|
||||
`items=${inventory.data?.items?.length ?? 'missing'}; ${trace(inventory.response)}`, OPTIONS)
|
||||
const inventoryItems = Array.isArray(inventory.data?.items) ? inventory.data.items : []
|
||||
context.assert(MODULE, `${destinationType}实收形成服务端SKU库存账`, inventory.response,
|
||||
success(inventory.response) && inventoryItems.length > 0
|
||||
&& inventoryItems.every((item) => nonBlank(item?.skuCode) && Number(item?.availablePackages) > 0),
|
||||
`skuCodes=${[...new Set(inventoryItems.map((item) => item?.skuCode).filter(nonBlank))].join('|') || 'missing'}, availablePackages=${inventoryItems.reduce((total, item) => total + Number(item?.availablePackages || 0), 0)}; ${trace(inventory.response)}`, OPTIONS)
|
||||
|
||||
const occupied = [...inventoryItems].sort((left, right) =>
|
||||
Number(right?.availablePackages || 0) - Number(left?.availablePackages || 0))[0]
|
||||
const actualPalletCode = occupied?.palletCode || pallet.palletCode
|
||||
const actualPalletId = id(occupied?.palletId || pallet.palletId)
|
||||
const actualLocationCode = occupied?.locationCode || pallet.locationCode
|
||||
const actualLocationId = id(occupied?.locationId || pallet.locationId)
|
||||
const location = await pda(context, token, 'POST', '完成入库后扫码查询库位',
|
||||
'/api/pda/v1/last-leg/locations/resolve', { code: pallet.locationCode })
|
||||
'/api/pda/v1/last-leg/locations/resolve', { code: actualLocationCode })
|
||||
context.assert(MODULE, '库位查询返回当前仓真实占用汇总', location.response,
|
||||
success(location.response) && id(location.data?.locationId) === pallet.locationId
|
||||
&& location.data?.locationCode === pallet.locationCode
|
||||
success(location.response) && id(location.data?.locationId) === actualLocationId
|
||||
&& location.data?.locationCode === actualLocationCode
|
||||
&& Number(location.data?.occupiedPackages) > 0 && Number(location.data?.inventoryPositionCount) > 0,
|
||||
`locationId=${id(location.data?.locationId) || 'missing'}; ${trace(location.response)}`, OPTIONS)
|
||||
|
||||
const resolvedPallet = await pda(context, token, 'POST', '完成入库后扫码查询托盘内容',
|
||||
'/api/pda/v1/last-leg/pallets/resolve', { code: pallet.palletCode })
|
||||
'/api/pda/v1/last-leg/pallets/resolve', { code: actualPalletCode })
|
||||
context.assert(MODULE, '托盘查询返回当前位置与库存明细', resolvedPallet.response,
|
||||
success(resolvedPallet.response) && id(resolvedPallet.data?.palletId) === pallet.palletId
|
||||
&& id(resolvedPallet.data?.locationId) === pallet.locationId
|
||||
success(resolvedPallet.response) && id(resolvedPallet.data?.palletId) === actualPalletId
|
||||
&& id(resolvedPallet.data?.locationId) === actualLocationId
|
||||
&& Array.isArray(resolvedPallet.data?.inventory) && resolvedPallet.data.inventory.length > 0
|
||||
&& Number(resolvedPallet.data?.occupiedPackages) > 0,
|
||||
`palletId=${id(resolvedPallet.data?.palletId) || 'missing'}; ${trace(resolvedPallet.response)}`, OPTIONS)
|
||||
@@ -242,7 +249,8 @@ async function verifyWarehouseQueries(context, token, inboundCode, pallet, desti
|
||||
&& Number(history.data?.page) === 1 && Number(history.data?.size) === 50,
|
||||
`records=${historyRows.length}; ${trace(history.response)}`, OPTIONS)
|
||||
return success(inventory.response) && success(location.response) && success(resolvedPallet.response)
|
||||
? { inboundCode, pallet: resolvedPallet.data, location: location.data, inventory: inventory.data?.items || [] }
|
||||
? { inboundCode, pallet: resolvedPallet.data, location: location.data,
|
||||
inventory: inventoryItems.filter((item) => id(item?.palletId) === actualPalletId) }
|
||||
: null
|
||||
}
|
||||
|
||||
@@ -804,24 +812,36 @@ async function runReceiving(context, token, secondaryToken, merchantToken, prefe
|
||||
if (context.createdResources.phase4OverseasPda.finalStatus === 'COMPLETED') {
|
||||
const physicalPallets = [...new Map([...pallets.values()]
|
||||
.map((item) => [id(item.palletId), item])).values()]
|
||||
context.createdResources.phase4OverseasPda.completedContainerFacts.push({
|
||||
containerNo,
|
||||
containerBookingId: id(preferredProducer?.containerBookingId),
|
||||
expectedPalletCost: physicalPallets.reduce((sum, item) => sum + Number(item.unitPrice || 0), 0),
|
||||
palletIds: physicalPallets.map((item) => item.palletId),
|
||||
})
|
||||
const generatedContainerPallets = current.data.inbounds.flatMap((item) =>
|
||||
context.createdResources.phase4OverseasPda.generatedPalletsByInbound[item.inboundCode] || [])
|
||||
const completedFixtures = []
|
||||
const order = await captureCompletedOrder(context, containerNo, preferredProducer?.tenantId)
|
||||
for (const inbound of current.data.inbounds.filter((item) => pallets.has(item.inboundCode))) {
|
||||
const warehouseFacts = await verifyWarehouseQueries(context, token, inbound.inboundCode,
|
||||
pallets.get(inbound.inboundCode), inbound.destinationType)
|
||||
if (warehouseFacts && context.context?.phase4OverseasPdaOperations) {
|
||||
context.context.phase4OverseasPdaOperations.completedFixtures.push({
|
||||
const fixture = {
|
||||
containerNo, order, destinationType: inbound.destinationType,
|
||||
fbaWarehouseCode: inbound.destinationType === 'FBA' ? inbound.fbaWarehouseCode : null,
|
||||
auxiliaryPallets: generatedContainerPallets.filter((candidate) =>
|
||||
id(candidate?.palletId) !== id(warehouseFacts.pallet?.palletId)),
|
||||
...warehouseFacts,
|
||||
})
|
||||
}
|
||||
context.context.phase4OverseasPdaOperations.completedFixtures.push(fixture)
|
||||
completedFixtures.push(fixture)
|
||||
}
|
||||
}
|
||||
const receivedPallets = [...new Map(completedFixtures.map((fixture) => {
|
||||
const palletId = id(fixture.pallet?.palletId)
|
||||
const source = physicalPallets.find((candidate) => id(candidate?.palletId) === palletId)
|
||||
return [palletId, { palletId, unitPrice: Number(source?.unitPrice || 0) }]
|
||||
}).filter(([palletId]) => longId(palletId))).values()]
|
||||
context.createdResources.phase4OverseasPda.completedContainerFacts.push({
|
||||
containerNo,
|
||||
containerBookingId: id(preferredProducer?.containerBookingId),
|
||||
expectedPalletCost: receivedPallets.reduce((sum, item) => sum + item.unitPrice, 0),
|
||||
palletIds: receivedPallets.map((item) => item.palletId),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user