diff --git a/server/src/services/customerBudgetService.ts b/server/src/services/customerBudgetService.ts index 2f09cef..ee59375 100644 --- a/server/src/services/customerBudgetService.ts +++ b/server/src/services/customerBudgetService.ts @@ -1,4 +1,5 @@ import { pool } from '../db'; +import { isIndependentInboundCustomer } from './independentInbound'; export type CreditCheckLevel = 'ok' | 'block'; @@ -23,6 +24,25 @@ export async function checkCustomerCredit( FROM customers WHERE customer_code = $1`, [customerCode] ); + /** + * 「独立进货」哨兵客户(2026-10-12 开发者):它不是真实客户、也不产生应收 + * ⇒ **不参与信用/预算校验**,直接放行。 + * ⚠️ 必须修在**这一层**:录单页提交前会调 `GET /workflow/finance/customer/:code/can-order` + * (`checkCustomerOrderBudget` 包装 → 本函数),只改 submit 服务层挡不住它 —— 开发者截图报障的就是这条。 + * 「信用不拦单、唯一 block 是客户不存在」这条冻结口径对**真实客户**完全不变。 + */ + if (isIndependentInboundCustomer(customerCode)) { + return { + allowed: true, + level: 'ok', + message: '', + creditFrozen: false, + creditLimit: 0, + usedBudget: 0, + orderAmount: Math.max(0, Number(orderAmount) || 0), + projectedUsed: Math.max(0, Number(orderAmount) || 0), + } as CustomerCreditCheck; + } const orderAmt = Math.max(0, Number(orderAmount) || 0); const base = { creditFrozen: false, diff --git a/server/tests/independentInbound.test.ts b/server/tests/independentInbound.test.ts index a5f5189..e0bb7dd 100644 --- a/server/tests/independentInbound.test.ts +++ b/server/tests/independentInbound.test.ts @@ -179,6 +179,29 @@ describe('③b 结构上零销售:录单写 0 售价、零价闸门对哨兵 }); }); +describe('③c 信用校验:修在**最底层**函数上(否则录单页的预检接口仍报"客户不存在")', () => { + const budget = svc('src/services/customerBudgetService.ts'); + + it('checkCustomerCredit 对哨兵直接返回 allowed(覆盖所有包装/接口)', () => { + const idx = budget.indexOf('export async function checkCustomerCredit'); + expect(idx).toBeGreaterThan(-1); + const body = budget.slice(idx, idx + 1600); + expect(body).toContain('isIndependentInboundCustomer(customerCode)'); + expect(body).toContain("level: 'ok'"); + // 必须在查 customers 之后仍无条件放行(真实客户逻辑不变) + expect(body).toContain('FROM customers WHERE customer_code = $1'); + // 冻结口径:真实客户仍只有"不存在"才 block + expect(budget).toContain('不存在,无法下单'); + }); + + it('录单页提交前预检接口链路存在(GET /finance/customer/:code/can-order → checkCustomerOrderBudget)', () => { + const routes = svc('src/modules/workflow/routes/financeRoutes.ts'); + expect(routes).toContain("'/finance/customer/:customerCode/can-order'"); + expect(routes).toContain('checkCustomerOrderBudget'); + expect(budget).toContain('export async function checkCustomerOrderBudget'); + }); +}); + describe('④ 不计入销售(口径谓词统一,成本口径不动)', () => { it('统一谓词来自 new 模块', () => { expect(sentinel).toContain('export function salesVisibleOrderSql');