test(overseas): close fulfillment HTTP gaps

This commit is contained in:
2026-09-09 03:18:59 +08:00
parent 47774ea8fe
commit a99a54493b
4 changed files with 27 additions and 6 deletions
@@ -321,18 +321,36 @@ export async function run(context) {
context.assert(MODULE, '退回候选严格属于当前派送单', returnOptions.response,
Boolean(returnInbound), `candidate=${Boolean(returnInbound)}; ${trace(returnOptions.response)}`, OPTIONS)
if (!returnInbound) return
const returnSource = Array.isArray(returnInbound.returnSources)
? returnInbound.returnSources.find((value) => id(value?.outboundPalletItemId)
&& id(value?.inventoryPositionId) && Number(value?.maxReturnPackages) > 0) : null
context.assert(MODULE, '退回候选包含可追溯的出库托盘库存来源', returnOptions.response,
Boolean(returnSource), `source=${Boolean(returnSource)}; ${trace(returnOptions.response)}`, OPTIONS)
if (!returnSource) return
const returnBody = {
inboundOrderId: id(returnInbound.inboundOrderId), reason: `${context.marker}-delivery-return`,
returnDirection: 'OVERSEAS_WAREHOUSE', returnLogisticsNo: `${context.marker}-RETURN`.slice(0, 128),
items: [{
outboundPalletItemId: id(returnSource.outboundPalletItemId),
inventoryPositionId: id(returnSource.inventoryPositionId),
packageCount: 1,
}],
idempotencyKey: key(context, 'DELIVERY-RETURN'),
}
const returned = await platform(context, 'POST', '标记派送退回海外仓并创建退货异常',
query(`${LASTLEG_BASE}/delivery-orders/${encodeURIComponent(deliveryNo)}/mark-return`, { customerId }), {
inboundOrderId: id(returnInbound.inboundOrderId), reason: `${context.marker}-delivery-return`,
returnDirection: 'OVERSEAS_WAREHOUSE', returnLogisticsNo: `${context.marker}-RETURN`.slice(0, 128),
packageCount: 1, skuCode: null,
})
query(`${LASTLEG_BASE}/delivery-orders/${encodeURIComponent(deliveryNo)}/mark-return`, { customerId }), returnBody)
const returnExceptionNo = id(returned.data?.exceptionNo)
context.assert(MODULE, '派送退回生成独立PENDING异常单', returned.response,
nonBlank(returnExceptionNo) && returned.data?.status === 'PENDING'
&& returnExceptionNo !== manualExceptionNo, trace(returned.response), OPTIONS)
context.createdResources.phase5OverseasFulfillment.returnExceptionNo = returnExceptionNo || null
const returnReplay = await platform(context, 'POST', '派送退回同键同载荷重放',
query(`${LASTLEG_BASE}/delivery-orders/${encodeURIComponent(deliveryNo)}/mark-return`, { customerId }), returnBody)
context.assert(MODULE, '派送退回重放复用同一异常单', returnReplay.response,
returnReplay.data?.replayed === true && id(returnReplay.data?.exceptionNo) === returnExceptionNo,
trace(returnReplay.response), OPTIONS)
const delivery = await platform(context, 'GET', '回查派送退回终态',
query(`${LASTLEG_BASE}/delivery-orders/${encodeURIComponent(deliveryNo)}`, { customerId }))
context.assert(MODULE, '派送退回后单据状态为RETURN_PENDING且保留出库关联', delivery.response,