fix finance reconciliation fee pool ids

This commit is contained in:
2026-08-12 14:21:25 +08:00
parent aaa38f825a
commit 60895e3bf5
2 changed files with 25 additions and 11 deletions
@@ -20,6 +20,11 @@ function settlementId(value) { return id(value?.settlementId ?? value?.id) }
function sourceId(value) { return id(value?.feeSourceId ?? value?.financeFeeSourceId ?? value?.id) }
function sourceDate(value) { return value?.businessDate ?? value?.billingDate ?? value?.feeDate ?? '' }
function sourceWaybill(value) { return id(value?.waybillId ?? value?.shipmentId ?? value?.orderId ?? value?.inboundId ?? value?.sourceNo) }
function financePoolId(value) {
const poolItemId = id(value?.poolItemId)
if (poolItemId) return poolItemId.includes(':') ? poolItemId.slice(poolItemId.indexOf(':') + 1) : poolItemId
return id(value?.feeSourceId ?? value?.financeFeeSourceId ?? value?.id)
}
function isUnboundContainerCost(raw) {
return raw?.sourceType === 'MANUAL' && raw?.billingBasis === 'CONTAINER_SHARED'
&& !sourceWaybill(raw)
@@ -68,16 +73,21 @@ function blocker(context, name, evidence, category, response = null) {
{ marker: context.marker, ...diagnostic(response) })
}
function normalizeFixture(context) {
async function normalizeFixture(context) {
const root = context.createdResources?.financeFullFixtures
if (!root || root.marker !== context.marker || !root.customerId
|| !Array.isArray(root.orders) || !Array.isArray(root.feeSources)) return null
const customerId = id(root.customerId)
const orders = new Map(root.orders.map((order) => [id(order.orderId ?? order.id), order]))
const poolResponse = await context.request('GET',
`${BASE}/fee-pool?customerId=${encodeURIComponent(customerId)}&direction=ALL`)
const pool = rows(poolResponse?.body?.data).filter((item) => String(item?.sourceType ?? '') !== 'MANUAL_COST')
const poolBySource = new Map(pool.map((item) => [id(item?.sourceId), item]))
const attemptedSources = root.feeSources.map((raw) => {
const order = orders.get(id(raw.orderId))
const financeSource = poolBySource.get(sourceId(raw))
return {
raw, feeSourceId: sourceId(raw), customerId: id(raw.customerId ?? customerId),
raw, feeSourceId: financePoolId(financeSource), sourceFeeId: sourceId(raw), customerId: id(raw.customerId ?? customerId),
direction: String(raw.direction ?? ''), currency: String(raw.currency ?? raw.currencyCode ?? '').toUpperCase(),
businessDate: sourceDate(raw), waybillId: sourceWaybill(raw) || sourceWaybill(order),
marker: raw.marker ?? root.marker,
@@ -195,7 +205,7 @@ async function createReceivable(context, statement, index) {
export async function run(context) {
const start = context.steps.length
const fixture = normalizeFixture(context)
const fixture = await normalizeFixture(context)
if (!fixture) {
blocker(context, '取得本轮财务全量 Fixture',
'financeFullFixtures 必须提供匹配 marker 的 customerId/orders/feeSources;禁止猜测旧字段或历史来源',