fix(fleet): retain unavailable source cost shares for multi-stop trips
This commit is contained in:
@@ -12,9 +12,18 @@ export function operationsFixtureFromHandover(bytes, { sha256, marker, runId })
|
||||
|| f.departure?.tripNo !== f.tripNo || f.departure.status !== 'IN_TRANSIT' || !Number.isFinite(Date.parse(f.departure.departedAt))
|
||||
|| snapshot.trip.departedAt !== f.departure.departedAt || !load?.manifestHash
|
||||
|| c?.status !== 'VERIFIED' || c.marker !== marker || c.tripNo !== f.tripNo
|
||||
|| c.expected?.finalCny !== '100.03' || c.expected?.usd !== '13.07' || c.expected?.allocationMethod !== 'SAME_ROUTE_PALLET_SPACES') fail()
|
||||
|| c.expected?.finalCny !== '100.03' || c.expected?.usd !== '13.07') fail()
|
||||
const positive = value => Number.isSafeInteger(Number(value)) && Number(value) > 0
|
||||
if (!Array.isArray(load.pallets) || !load.pallets.length || !Array.isArray(load.cargo) || !load.cargo.length || !Array.isArray(c.shares) || !c.shares.length) fail()
|
||||
const stops = snapshot.trip.stops
|
||||
if (!Array.isArray(stops) || load.pallets.some(p => !Number.isSafeInteger(p.deliveryIndex) || p.deliveryIndex <= 0
|
||||
|| p.deliveryIndex >= stops.length || !stops[p.deliveryIndex]?.destinationKey
|
||||
|| !load.cargo.some(row => String(row.warehousePalletId) === String(p.warehousePalletId))
|
||||
|| load.cargo.filter(row => String(row.warehousePalletId) === String(p.warehousePalletId)).some(row => row.destinationKey !== stops[p.deliveryIndex].destinationKey))) fail()
|
||||
const sameRoute = new Set(load.pallets.map(p => p.deliveryIndex)).size === 1
|
||||
if (sameRoute ? c.expected.allocationMethod !== 'SAME_ROUTE_PALLET_SPACES' || c.expected.allocationStatus !== 'AVAILABLE'
|
||||
: c.expected.allocationMethod !== null || c.expected.allocationStatus !== 'UNAVAILABLE'
|
||||
|| c.expected.allocationBlockReason !== '各票卸货站不同,暂不可按同路线托位自动分摊') fail()
|
||||
const pallets = new Map()
|
||||
for (const p of load.pallets) { if (!p.warehousePalletId || pallets.has(String(p.warehousePalletId)) || !positive(p.palletSpaces)) fail(); pallets.set(String(p.warehousePalletId), Number(p.palletSpaces)) }
|
||||
const seen = new Set(), shipped = new Map()
|
||||
@@ -53,6 +62,7 @@ export function operationsFixtureFromHandover(bytes, { sha256, marker, runId })
|
||||
const total = [...shipped.values()].reduce((a, b) => a + b, 0), ext = [...external.values()].reduce((a, b) => a + b, 0)
|
||||
if (total !== Number(f.departure.shippedPackages) || ext <= 0 || ext >= total) fail()
|
||||
const costs = [['CNY', '100.03'], ['USD', '13.07']].map(([currency, amount]) => {
|
||||
if (!sameRoute) return { currency, directCost: Number(amount), ownCost: null, externalCost: null }
|
||||
const allocations = expectedAllocations(amount, c.shares)
|
||||
const sum = type => Number(allocations.filter(row => row.sourceType === type).reduce((n, row) => n + BigInt(row.cents), 0n)) / 100
|
||||
return { currency, directCost: Number(amount), ownCost: sum('OWN'), externalCost: sum('EXTERNAL') }
|
||||
|
||||
Reference in New Issue
Block a user