完善企业编辑页面并修复采购建单重试

This commit is contained in:
2026-10-30 15:42:38 +08:00
parent d6ef770e48
commit 55868177cd
19 changed files with 568 additions and 224 deletions
@@ -1,8 +1,23 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import ts from 'typescript'
const source = readFileSync(new URL('./inboundBilling.ts', import.meta.url), 'utf8')
const { getChargeModeLabel } = await import(`data:text/javascript;base64,${Buffer.from(ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022 },
}).outputText).toString('base64')}`)
test('describes the quantity basis from the published fee instead of treating the charge unit as the basis', () => {
assert.equal(getChargeModeLabel('KG', 393, 3.6894, 616.1298), '按体积重计费')
assert.equal(getChargeModeLabel('KG', 700, 3.6894, 616.1298), '按毛重计费')
assert.equal(getChargeModeLabel('KG', 616.1298, 3.6894, 616.1298), '按毛重计费')
assert.equal(getChargeModeLabel('CBM', 600, 1.2, 1.6), '按重量折算体积计费')
assert.equal(getChargeModeLabel('CBM', 600, 2, 1.6), '按体积计费')
assert.equal(getChargeModeLabel('CBM', 600, 1.6, 1.6), '按体积计费')
assert.equal(getChargeModeLabel('KG', 393, 3.6894, Number.NaN), '-')
assert.equal(getChargeModeLabel('KG', Number.POSITIVE_INFINITY, 3.6894, 616.1298), '-')
})
test('formats zero values, currencies, measurements, and backend dates without hardcoded business factors', () => {
assert.match(source, /value === null \|\| value === undefined/)
+12 -2
View File
@@ -36,8 +36,18 @@ export function formatInboundDateTime(value: string | null | undefined) {
}).format(date)
}
export function getChargeModeLabel(value: 'KG' | 'CBM') {
return value === 'KG' ? '按重量计费' : '按体积计费'
export function getChargeModeLabel(
chargeMode: 'KG' | 'CBM',
actualWeightKg: number,
actualVolumeCbm: number,
convertedQuantity: number,
) {
const actualQuantity = chargeMode === 'KG' ? actualWeightKg : actualVolumeCbm
if (!Number.isFinite(actualQuantity) || !Number.isFinite(convertedQuantity)) return '-'
const usesConvertedQuantity = convertedQuantity > actualQuantity
return chargeMode === 'KG'
? usesConvertedQuantity ? '按体积重计费' : '按毛重计费'
: usesConvertedQuantity ? '按重量折算体积计费' : '按体积计费'
}
export function getTaxModeLabel(value: string) {