This commit is contained in:
2026-10-21 21:30:24 +08:00
parent 234216b3eb
commit 5356a8c898
28 changed files with 1543 additions and 45 deletions
@@ -258,8 +258,27 @@ async function loadPublishedAutomaticFee(context, resource) {
actualWeightKg: responseWeightKg, actualVolumeCbm: responseVolumeCbm }
}
async function loadSupplier(context, category) {
export async function loadSupplier(context, category) {
if (context.financeFixtureHooks?.loadSupplier) return context.financeFixtureHooks.loadSupplier(context, category)
if (context.options?.fixedCustomerId) {
for (let page = 1; ; page += 1) {
const response = await request(context, 'GET', `/api/platform/v1/suppliers?tenantId=0&status=ACTIVE&page=${page}&size=100`)
const data = context.apiSuccess(MODULE, '读取可复用的现有供应商', response, '', OPTIONS)
if (!data) return null
const records = rows(data)
const candidate = records.find(item => id(item?.id) && item.status === 'ACTIVE' && (!category || item.category === category))
if (candidate) {
const detailResponse = await request(context, 'GET', `/api/platform/v1/suppliers/${encodeURIComponent(candidate.id)}?tenantId=0`)
const detail = context.apiSuccess(MODULE, '核对复用供应商状态与类别', detailResponse, '', OPTIONS)
if (id(detail?.id) === id(candidate.id) && detail?.status === 'ACTIVE' && (!category || detail.category === category)) return detail
blocker(context, '复用供应商已变化', '候选详情不匹配,不创建替代供应商')
return null
}
if (!records.length || page * 100 >= Number(data.total ?? records.length)) break
}
blocker(context, '缺少可复用供应商', `需要 ACTIVE ${category || '任意类别'} 供应商;禁止自动创建`)
return null
}
const effectiveCategory = category || 'BOOKING'
const body = buildSupplierBody(context.marker, effectiveCategory)
const response = await request(context, 'POST', '/api/platform/v1/suppliers?tenantId=0', body)