This commit is contained in:
2026-08-19 09:14:35 +08:00
parent c188482c24
commit 80cfca5056
36 changed files with 854 additions and 1044 deletions
@@ -2,7 +2,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
import { http } from '@/shared/api/http'
import {
adjustInboundFeeDetail, createInboundFeeDetail, deleteInboundFeeDetail, listInboundFeeDetails,
reviewInboundFeeDetail, updateInboundFeeDetail, voidInboundFeeDetail, type SaveInboundFeeDetailRequest,
listInboundFeeItemOptions, listInboundFeeSupplierOptions, reviewInboundFeeDetail,
updateInboundFeeDetail, voidInboundFeeDetail, type SaveInboundFeeDetailRequest,
} from './inboundFeeDetails'
vi.mock('@/shared/api/http', async () => {
@@ -18,7 +19,7 @@ describe('inbound fee-detail API', () => {
})
it('maps the complete write contract and optimistic version', async () => {
const payload: SaveInboundFeeDetailRequest = { feeItemId: '31', direction: 'PAYABLE', businessDate: '2026-08-12', unitPrice: 12.5, currency: 'CNY', amount: 125, settlementIncluded: true, partnerId: '41', partnerName: '测试供应商', remark: '验收' }
const payload: SaveInboundFeeDetailRequest = { feeItemId: '31', direction: 'PAYABLE', businessDate: '2026-08-12', unitPrice: 12.5, currency: 'CNY', amount: 125, supplierId: '41', remark: '验收' }
vi.mocked(http.get).mockResolvedValue({ code: '200', message: 'success', data: [] })
vi.mocked(http.post).mockResolvedValue({ code: '200', message: 'success', data: null })
vi.mocked(http.put).mockResolvedValue({ code: '200', message: 'success', data: payload })
@@ -32,4 +33,31 @@ describe('inbound fee-detail API', () => {
expect(http.post).toHaveBeenCalledWith('/platform/v1/inbounds/88/fee-details/11/void', { expectedSourceVersion: 3 }, { params: { accountId: '100' } })
expect(http.delete).toHaveBeenCalledWith('/platform/v1/inbounds/88/fee-details/11', { params: { accountId: '100' } })
})
it('fails closed when a fee item has no recognized supplier category', async () => {
vi.mocked(http.get).mockResolvedValue({ code: '200', data: { records: [
{ id: 31, feeTypeName: '拖车费', feeCode: 'TRUCKING', supplierCategory: 'TRUCKING', warehousePayable: true },
{ id: 32, feeTypeName: '未知费用', feeCode: 'UNMAPPED', supplierCategory: 'UNKNOWN', warehousePayable: true },
{ id: 33, feeTypeName: '缺少类别', feeCode: 'MISSING', warehousePayable: true },
] } })
await expect(listInboundFeeItemOptions()).resolves.toMatchObject([
{ id: 31, feeCode: 'TRUCKING', supplierCategory: 'TRUCKING' },
{ id: 32, feeCode: 'UNMAPPED', supplierCategory: null },
{ id: 33, feeCode: 'MISSING', supplierCategory: null },
])
})
it('requests and retains only ACTIVE suppliers in the required category', async () => {
vi.mocked(http.get).mockResolvedValue({ code: '200', data: { records: [
{ id: 41, tenantId: 0, name: '承运商A', category: 'TRUCKING', status: 'ACTIVE', version: 1, deleted: false },
{ id: 42, tenantId: 0, name: '停用承运商', category: 'TRUCKING', status: 'INACTIVE', version: 1, deleted: false },
{ id: 43, tenantId: 0, name: '报关行', category: 'CUSTOMS', status: 'ACTIVE', version: 1, deleted: false },
], page: 1, size: 200, total: 3, pages: 1 } })
await expect(listInboundFeeSupplierOptions('TRUCKING')).resolves.toEqual([
{ id: '41', supplierName: '承运商A', category: 'TRUCKING' },
])
expect(http.get).toHaveBeenCalledWith('/platform/v1/suppliers', { params: {
page: 1, size: 200, category: 'TRUCKING', region: undefined, status: 'ACTIVE', keyword: undefined,
} })
})
})
@@ -1,4 +1,5 @@
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
import { listSuppliers, type SupplierCategory } from '@/modules/suppliers'
export type InboundFeeDirection = 'RECEIVABLE' | 'PAYABLE'
export type InboundFeeReviewStatus = 'PENDING' | 'APPROVED' | 'REJECTED'
@@ -11,8 +12,9 @@ export interface InboundFeeDetail {
sourceFeeVersion: number
inboundCode: string | null
direction: InboundFeeDirection
partnerId: string | number | null
partnerName: string | null
supplierId: string | number | null
supplierName: string | null
supplierCategory: SupplierCategory | null
businessDate: string
customerName: string | null
feeTypeNameSnapshot: string
@@ -25,7 +27,6 @@ export interface InboundFeeDetail {
reviewerName: string | null
reviewedAt: string | null
publicationStatus: string
settlementIncluded: boolean
}
export interface SaveInboundFeeDetailRequest {
@@ -35,20 +36,26 @@ export interface SaveInboundFeeDetailRequest {
unitPrice: number
currency: string
amount: number
settlementIncluded: boolean
partnerId: string | number | null
partnerName: string | null
supplierId: string | number | null
remark: string | null
}
export interface InboundFeeItemOption {
id: string | number
feeTypeName: string
feeCode: string
supplierCategory: SupplierCategory | null
warehousePayable: boolean
warehouseReceivable: boolean
}
export interface InboundFeePartnerOption { id: string | number; partnerName: string }
export interface InboundFeeSupplierOption { id: string; supplierName: string; category: SupplierCategory }
const supplierCategories: SupplierCategory[] = ['BOOKING', 'CUSTOMS', 'TRUCKING', 'CERTIFICATE']
function supplierCategory(value: unknown): SupplierCategory | null {
return supplierCategories.includes(value as SupplierCategory) ? value as SupplierCategory : null
}
function basePath(inboundId: string) {
const identifier = String(inboundId ?? '').trim()
@@ -95,15 +102,22 @@ export async function voidInboundFeeDetail(accountId: string, inboundId: string,
}
export async function listInboundFeeItemOptions() {
const response = await http.get<unknown, ApiEnvelope<{ records: InboundFeeItemOption[] }>>(
const response = await http.get<unknown, ApiEnvelope<{ records: Record<string, unknown>[] }>>(
'/platform/v1/fee-items', { params: { status: 'ACTIVE', page: 1, size: 200 } },
)
return unwrapApiResponse(response).records || []
return (unwrapApiResponse(response).records || []).map((raw): InboundFeeItemOption => ({
id: raw.id as string | number,
feeTypeName: String(raw.feeTypeName || ''),
feeCode: String(raw.feeCode || ''),
supplierCategory: supplierCategory(raw.supplierCategory),
warehousePayable: Boolean(raw.warehousePayable),
warehouseReceivable: Boolean(raw.warehouseReceivable),
}))
}
export async function listInboundFeePartnerOptions() {
const response = await http.get<unknown, ApiEnvelope<{ records: InboundFeePartnerOption[] }>>(
'/platform/v1/partners', { params: { status: 'ACTIVE', page: 1, size: 200 } },
)
return unwrapApiResponse(response).records || []
export async function listInboundFeeSupplierOptions(category: SupplierCategory) {
const page = await listSuppliers({ status: 'ACTIVE', category, page: 1, size: 200 })
return page.records.filter((supplier) => supplier.status === 'ACTIVE' && supplier.category === category).map((supplier): InboundFeeSupplierOption => ({
id: supplier.id, supplierName: supplier.name, category: supplier.category,
}))
}
@@ -255,7 +255,6 @@ export interface UnifiedOrderFeeDetailResource {
inboundedAt: string | null
outboundAt?: string | null
storageDays?: number | null
settlementIncluded: boolean | null
billNo?: string | null
settlementStartDate?: string | null
settlementEndDate?: string | null