fix(supply-chain): 清空停产退市商品限价

(cherry picked from commit 42b374801df5926aba8f302af518a538e2baede1)
This commit is contained in:
居居 2026-10-20 17:14:45 +08:00 committed by WuYongJie
parent 0509df6408
commit 1c1efebf27
4 changed files with 70 additions and 14 deletions

View File

@ -0,0 +1,38 @@
import { resolveLimitPriceFields } from './supply-chain-limit-price-fields'
const ACTIVE_INPUT = {
productStatus: '销售',
ownerLimitPrice: 286.9,
costPrice: '128.50',
limitUpdatedAt: new Date('2026-04-21T20:54:00.000Z'),
limitInitiator: '玉衡',
}
describe('resolveLimitPriceFields', () => {
it('calculates all limit price fields for an active product', () => {
const fields = resolveLimitPriceFields(ACTIVE_INPUT)
expect(fields.opsPriceLimit).toBe('286.90')
expect(fields.nonOwnerLimitPriceNew).toBe('301.25')
expect(fields.limitInitiator).toBe('玉衡')
})
it.each(['停产', ' 退市 '])('clears every limit field for %s products', (productStatus) => {
const fields = resolveLimitPriceFields({
...ACTIVE_INPUT,
productStatus,
})
expect(fields).toEqual({
opsPriceLimit: '',
nonOwnerLimitPriceNew: '',
jxLimitPrice: '',
alibabaPageLimitPrice: '',
distributorPrice89: '',
distributorPrice85: '',
distributorPrice80: '',
limitUpdatedAt: '',
limitInitiator: '',
})
})
})

View File

@ -3,24 +3,37 @@
* 负责人限价来自限价流程(货号维度);其余字段按固定公式从负责人限价 / 成本价推导。
* 供限价明细页查询(service)与导出(export service)共用。
*/
const INACTIVE_PRODUCT_STATUSES = new Set(['停产', '退市'])
function emptyLimitPriceFields() {
return {
opsPriceLimit: '',
nonOwnerLimitPriceNew: '',
jxLimitPrice: '',
alibabaPageLimitPrice: '',
distributorPrice89: '',
distributorPrice85: '',
distributorPrice80: '',
limitUpdatedAt: '',
limitInitiator: '',
}
}
export function resolveLimitPriceFields(input: {
productStatus: string
ownerLimitPrice: number | null
costPrice: string
limitUpdatedAt: Date | null
limitInitiator: string
}) {
if (INACTIVE_PRODUCT_STATUSES.has(input.productStatus.trim())) {
return emptyLimitPriceFields()
}
const owner = input.ownerLimitPrice
const format = (value: number | null) => (value === null ? '' : value.toFixed(2))
if (owner === null) {
return {
opsPriceLimit: '',
nonOwnerLimitPriceNew: '',
jxLimitPrice: '',
alibabaPageLimitPrice: '',
distributorPrice89: '',
distributorPrice85: '',
distributorPrice80: '',
limitUpdatedAt: '',
...emptyLimitPriceFields(),
limitInitiator: input.limitInitiator,
}
}

View File

@ -218,10 +218,19 @@ export class SupplyChainProductArchiveExportService {
currentStorageType: row.storageType,
config,
})
const styleLimit = styleLimitByCode.get(String(record.sku ?? '').trim())
const limitFields = resolveLimitPriceFields({
productStatus: row.productStatus,
ownerLimitPrice: styleLimit?.ownerLimitPrice ?? null,
costPrice: String(row.costPrice ?? ''),
limitUpdatedAt: styleLimit?.approvedAt ?? null,
limitInitiator: styleLimit?.initiator ?? '',
})
if (!ownerEmploymentIndex) {
return {
...row,
...warehouseFields,
...limitFields,
} satisfies SupplyChainProductArchiveRow
}
return {
@ -230,12 +239,7 @@ export class SupplyChainProductArchiveExportService {
...warehouseFields,
opsHead: resolveOwnerTakeover(record.opsHead ?? '', ownerEmploymentIndex).display || row.opsHead,
designer: resolveDesignerView(record.designer ?? '', ownerEmploymentIndex).display || row.designer,
...resolveLimitPriceFields({
ownerLimitPrice: styleLimitByCode.get(String(record.sku ?? '').trim())?.ownerLimitPrice ?? null,
costPrice: String(row.costPrice ?? ''),
limitUpdatedAt: styleLimitByCode.get(String(record.sku ?? '').trim())?.approvedAt ?? null,
limitInitiator: styleLimitByCode.get(String(record.sku ?? '').trim())?.initiator ?? '',
}),
...limitFields,
} satisfies SupplyChainProductArchiveRow
}
}

View File

@ -145,6 +145,7 @@ export class SupplyChainProductArchiveService {
// 限价派生字段(限价明细页 / 导出共用):负责人限价 + 非负责人 / 京喜 / 阿里 / 分销商折扣
const styleLimit = styleLimitByCode.get(String(record.sku ?? '').trim())
const limitFields = resolveLimitPriceFields({
productStatus: row.productStatus,
ownerLimitPrice: styleLimit?.ownerLimitPrice ?? null,
costPrice: String(row.costPrice ?? ''),
limitUpdatedAt: styleLimit?.approvedAt ?? null,