优化
This commit is contained in:
@@ -6,6 +6,8 @@ const STATEMENT_LIST_PERMISSION = 'platform:finance:customer-statement:list'
|
||||
const LEGACY_STATEMENT_VIEW_PERMISSION = 'platform:finance:bill:view'
|
||||
const REQUIRED_PERMISSIONS = [
|
||||
'platform:finance:customer-account:list',
|
||||
'platform:finance:customer-arap:list',
|
||||
'platform:finance:fee-source:review',
|
||||
STATEMENT_LIST_PERMISSION,
|
||||
'platform:finance:reconciliation:create',
|
||||
'platform:finance:reconciliation:review',
|
||||
@@ -116,6 +118,31 @@ function finish(context, start) {
|
||||
failed: steps.filter((step) => !step.passed).length,
|
||||
})
|
||||
}
|
||||
|
||||
async function approveFixtureSources(context, fixture) {
|
||||
const approved = []
|
||||
for (const source of fixture.sources) {
|
||||
const detailResponse = await context.request('GET', `${BASE}/fee-sources/${encodeURIComponent(source.feeSourceId)}`)
|
||||
let detail = context.apiSuccess(MODULE, '回读本轮 Finance 费用来源审核状态', detailResponse,
|
||||
`feeSourceId=${source.feeSourceId}`, OPTIONS)
|
||||
if (!detail) return false
|
||||
if (detail.reviewStatus === 'PENDING') {
|
||||
const reviewResponse = await write(context, 'POST', `${BASE}/fee-sources/${encodeURIComponent(source.feeSourceId)}/review`, {
|
||||
action: 'APPROVE', reason: context.marker, expectedVersion: Number(detail.operationVersion),
|
||||
}, `fee-source-review-${source.feeSourceId}`)
|
||||
detail = context.apiSuccess(MODULE, '审核本轮 Finance 费用来源', reviewResponse,
|
||||
`feeSourceId=${source.feeSourceId}`, OPTIONS)
|
||||
context.assert(MODULE, '费用来源审核后成为结算候选', reviewResponse,
|
||||
detail?.reviewStatus === 'APPROVED' && detail?.sourceStatus === 'AVAILABLE'
|
||||
&& detail?.statementGenerated === false,
|
||||
`feeSourceId=${source.feeSourceId}, reviewStatus=${detail?.reviewStatus ?? 'missing'}, sourceStatus=${detail?.sourceStatus ?? 'missing'}`, OPTIONS)
|
||||
}
|
||||
if (detail?.reviewStatus !== 'APPROVED') return false
|
||||
approved.push(source.feeSourceId)
|
||||
}
|
||||
fixture.root.approvedFinanceFeeSourceIds = approved
|
||||
return approved.length === fixture.sources.length
|
||||
}
|
||||
function diagnostic(response) {
|
||||
return { http: response?.http ?? null,
|
||||
code: response?.body?.code == null ? null : String(response.body.code),
|
||||
@@ -306,8 +333,7 @@ async function issueCompleteChain(context, statement) {
|
||||
statement = await act(context, statement, 'ISSUE', 'chain-issue-final')
|
||||
const actions = new Set(list(statement?.revisions).map((revision) => revision.action))
|
||||
context.assert(MODULE, '完整链保留驳回、重开、调整、作废和再次出账 revision', null,
|
||||
['RECONCILIATION_REJECT', 'RECONCILIATION_REOPEN', 'RECONCILIATION_ADJUST',
|
||||
'RECONCILIATION_VOID', 'RECONCILIATION_ISSUE'].every((action) => actions.has(action)),
|
||||
['REJECT', 'REOPEN', 'ADJUST', 'VOID', 'ISSUE'].every((action) => actions.has(action)),
|
||||
`actions=${[...actions].join(',')}`, OPTIONS)
|
||||
return statement
|
||||
}
|
||||
@@ -445,6 +471,13 @@ export async function run(context) {
|
||||
const groups = [cutoffSources, ...(() => {
|
||||
return [remainingSources.slice(0, 1), remainingSources.slice(1)]
|
||||
})()]
|
||||
if (!await approveFixtureSources(context, fixture)) {
|
||||
blocker(context, '本轮 Finance 费用来源全部审核通过',
|
||||
'费用来源未完成 PENDING -> APPROVED,禁止跳过审核直接生成对账单',
|
||||
'finance-fee-source-review-failed')
|
||||
finish(context, start)
|
||||
return
|
||||
}
|
||||
const issuedStatements = []
|
||||
for (let index = 0; index < groups.length; index += 1) {
|
||||
const created = await createStatement(context, groups[index], `selected-${index + 1}`,
|
||||
|
||||
Reference in New Issue
Block a user