fix(clearance): 优化批量审核折扣与原因校验

This commit is contained in:
居居 2026-11-27 16:59:12 +08:00
parent 5a08c6ee85
commit ffbb22604e
4 changed files with 137 additions and 13 deletions

View File

@ -449,6 +449,81 @@ describe('ClearanceReviewWorkbench', () => {
expect(screen.getByText('已将 2 条明细折扣统一设为 3 折')).toBeInTheDocument()
})
it('shows no discount as blank and submits no discount by default', async () => {
const noDiscountRow = {
...row,
discount: 1,
discountLabel: '',
}
global.fetch = jest.fn((input, init) => {
const requestUrl = new URL(String(input), 'http://localhost')
if (
requestUrl.pathname === '/api/supply-chain/clearance/review-workbench'
&& init?.method === 'POST'
) {
return jsonResponse({
count: 1,
stage: 'APPROVED',
approvedCount: 1,
awaitingConfirmationCount: 0,
})
}
return jsonResponse({
periodKey: '2026-11',
round: 1,
rounds: [1],
page: 1,
pageSize: 50,
total: 1,
totalPages: 1,
profitCenters: ['运营中心A'],
filterOptions: {},
rows: [noDiscountRow],
summary: { total: 1, barcodeCount: 1, applicantCount: 1, duplicateBarcodeCount: 0 },
status: requestUrl.searchParams.get('status') ?? 'ALL',
statusCounts: {
all: 1,
review: 1,
confirmation: 0,
returned: 0,
resubmitted: 0,
passed: 0,
adjusted: 0,
rejected: 0,
},
})
}) as jest.Mock
render(<ClearanceReviewWorkbench
periodKey="2026-11"
round={1}
onClose={jest.fn()}
onReviewed={jest.fn()}
/>)
expect(await screen.findByText('申请人A')).toBeInTheDocument()
const discountInput = screen.getByLabelText('SKU-A 审核折扣')
expect(discountInput).toHaveValue(null)
expect(discountInput).toHaveAttribute('placeholder', '无折扣')
expect(screen.queryByText('10折')).not.toBeInTheDocument()
fireEvent.click(screen.getByLabelText('选择 SKU-A 申请人A'))
fireEvent.click(screen.getByRole('button', { name: '审核通过' }))
await waitFor(() => {
const reviewCall = (global.fetch as jest.Mock).mock.calls.find(([url, init]) => (
String(url) === '/api/supply-chain/clearance/review-workbench'
&& init?.method === 'POST'
))
expect(reviewCall).toBeDefined()
const body = JSON.parse(String(reviewCall?.[1]?.body))
expect(body.items).toEqual([{
id: 'task-a',
taskQty: 20,
discount: 1,
}])
})
})
it('remembers user review preferences and resets them on demand', async () => {
const first = render(<ClearanceReviewWorkbench
userId="user-preferences"

View File

@ -290,6 +290,11 @@ function numberText(value: number | null) {
return value == null ? '—' : String(value)
}
function reviewDiscountInputValue(value: number) {
if (!Number.isFinite(value) || value >= 0.995) return ''
return String(Number((value * 10).toFixed(1)))
}
function monthLabel(periodKey: string) {
const [year, month] = periodKey.split('-')
return year && month ? `${year}年${Number(month)}月` : periodKey
@ -426,7 +431,7 @@ export function ClearanceReviewWorkbench({
row.taskId,
{
taskQty: String(row.taskQty),
discount: String(Number((row.discount * 10).toFixed(1))),
discount: reviewDiscountInputValue(row.discount),
},
])))
if (next.page !== page) setPage(next.page)
@ -715,7 +720,7 @@ export function ClearanceReviewWorkbench({
[row.taskId]: {
taskQty: event.target.value,
discount: current[row.taskId]?.discount
?? String(Number((row.discount * 10).toFixed(1))),
?? reviewDiscountInputValue(row.discount),
},
}))}
/>
@ -729,7 +734,8 @@ export function ClearanceReviewWorkbench({
min={1}
max={10}
step={0.1}
value={reviewValues[row.taskId]?.discount ?? String(Number((row.discount * 10).toFixed(1)))}
value={reviewValues[row.taskId]?.discount ?? reviewDiscountInputValue(row.discount)}
placeholder="无折扣"
disabled={!canEditReviewValues(row) || busy}
aria-label={`${row.barcode} 审核折扣`}
onChange={(event) => setReviewValues((current) => ({
@ -842,15 +848,16 @@ export function ClearanceReviewWorkbench({
}
const values = reviewValues[row.taskId] ?? {
taskQty: String(row.taskQty),
discount: String(Number((row.discount * 10).toFixed(1))),
discount: reviewDiscountInputValue(row.discount),
}
const taskQty = Number(values.taskQty)
const discount = Number(values.discount)
const discountText = String(values.discount ?? '').trim()
const discount = discountText ? Number(discountText) : 10
if (!Number.isInteger(taskQty) || taskQty < 1) {
setError(`${row.barcode} 的任务量必须是正整数`)
return
}
if (!Number.isFinite(discount) || discount < 1 || discount > 10) {
if (discountText && (!Number.isFinite(discount) || discount < 1 || discount > 10)) {
setError(`${row.barcode} 的折扣必须是 1–10 折`)
return
}

View File

@ -7167,6 +7167,55 @@ describe('supply-chain-clearance workflow', () => {
], { returnRows: false })
})
it('lets the reviewer set a discount when the operator did not provide a reason', async () => {
const task = {
...pendingTask,
id: 'task-no-reason',
barcode: 'SKU-NO-REASON',
status: 'PENDING',
taskQty: 100,
discount: 1 as never,
reason: '',
}
repository.findTasksByIds.mockResolvedValue([task] as never)
repository.listPoolItemsForTaskPeriod.mockResolvedValue([{
barcode: 'SKU-NO-REASON',
sku: 'SKU-NO-REASON',
salesStatus: '停产',
productStatus: '停产',
stockJianshang: 500,
stockFactory: 0,
totalStock: 500,
dailySales: '2',
availableDays: '250',
costPrice: 100,
extra: { profitCenter: '运营中心A', clearanceTotal: 500 },
}] as never)
await expect(supplyChainClearanceService.batchReviewTasks({
items: [{ id: task.id, taskQty: 100, discount: 0.5 }],
action: 'approve',
user,
})).resolves.toMatchObject({ stage: 'READY' })
expect(repository.writeTasksWithEvents).toHaveBeenCalledWith([
expect.objectContaining({
id: task.id,
update: expect.objectContaining({
status: 'READY',
taskQty: 100,
discount: '0.50',
clearancePrice: '50.000',
}),
event: expect.objectContaining({
action: 'APPROVE_ADJUST',
before: expect.objectContaining({ discount: 1 }),
after: expect.objectContaining({ discount: 0.5 }),
}),
}),
], { returnRows: false })
})
it('moves operator-confirmed tasks through final approval and deletes rejected non-resubmissions', async () => {
const confirmed = {
...pendingTask,

View File

@ -4825,13 +4825,6 @@ class SupplyChainClearanceService {
poolItem.skuFamilyHasSalesStatus,
poolItem.skuProductionStatus,
)
assertTaskReasonAllowed(
poolItem.salesStatus || poolItem.productStatus,
discount,
task.reason,
poolItem.skuFamilyHasSalesStatus,
poolItem.skuProductionStatus,
)
assertPoolTaskAllowed(poolItem)
assertFixedPriorityDiscountAllowed(poolItem, discount, task.priorityOverride)
assertDiscountRestrictionAllowed(