fix(cost): 历史订单成本固化,只有预估→实际允许升级
- 已有快照不再因成本版本变更而替换,历史订单成交价与成本保持固定 - 仅接单平台「预估 → 实际」履约结算允许 supersede - 补配价格只影响没有快照的订单;文档同步口径
This commit is contained in:
@@ -3,6 +3,7 @@ import test from 'node:test'
|
||||
|
||||
import {
|
||||
resolveCost,
|
||||
shouldSupersedeSnapshot,
|
||||
resolveGenericCosts,
|
||||
selectCostVersion,
|
||||
type CostItemRow,
|
||||
@@ -354,3 +355,11 @@ test('比例费用按退款后的净收入计算', () => {
|
||||
assert.equal(noRefund[0]?.totalAmountFen, 300)
|
||||
assert.equal(withRefund[0]?.totalAmountFen, 180)
|
||||
})
|
||||
|
||||
test('历史订单成本固化:只有预估→实际允许替换', () => {
|
||||
assert.equal(shouldSupersedeSnapshot(null, 'estimated'), true)
|
||||
assert.equal(shouldSupersedeSnapshot('estimated', 'estimated'), false)
|
||||
assert.equal(shouldSupersedeSnapshot('estimated', 'actual'), true)
|
||||
assert.equal(shouldSupersedeSnapshot('actual', 'estimated'), false)
|
||||
assert.equal(shouldSupersedeSnapshot('actual', 'actual'), false)
|
||||
})
|
||||
|
||||
@@ -243,6 +243,18 @@ export function resolveGenericCosts(
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 历史订单成本固化:已有快照不再因成本版本变更而替换。
|
||||
* 唯一允许的变化是「预估 → 实际」的履约结算升级。
|
||||
*/
|
||||
export function shouldSupersedeSnapshot(
|
||||
currentStage: string | null | undefined,
|
||||
nextStage: string,
|
||||
): boolean {
|
||||
if (!currentStage) return true
|
||||
return currentStage !== 'actual' && nextStage === 'actual'
|
||||
}
|
||||
|
||||
export type SyncCostSnapshotsResult = {
|
||||
scanned: number
|
||||
created: number
|
||||
@@ -351,6 +363,8 @@ export async function syncChannelCostSnapshots(
|
||||
continue
|
||||
}
|
||||
if (current) {
|
||||
// 历史订单成本/成交价已固化,只有「预估→实际」允许升级。
|
||||
if (!shouldSupersedeSnapshot(current.snapshot_stage, resolution.stage)) continue
|
||||
supersedeIds.push(Number(current.id))
|
||||
result.superseded += 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user