feat(独立进货): 入库优先级更高 —— 进货单一律走入库,普通客户照旧免入库(开发者裁决)
开发者 2026-10-12:「基本上不会存在免入库的厂商;如果是真设置了、但他这是独立进货的,
那么就得走入库才行 —— 这个优先级高一些;其他客户下单还是该免入库的免入库。」
实现(只对哨兵单生效,普通单谓词一字未改):
· preparationFulfillmentService.ensureInspectionsForOrder:
哨兵单把"免入库厂商集合 / 商品直送集合"置空 ⇒ **照常建待验**(否则永远进不了库、也收不了口);
· tryAdvanceOrderToInspection 的覆盖判定:新增 `inboundCoverageFilters` ——
普通单原样 `AND NOT ${supplierSkipInboundExistsSql(...)} AND NOT ${skuDirectDeliveryAppliesSql(...)}`,
哨兵单整个置空 ⇒ 该行必须靠**验收覆盖**才算齐套(保持既有字面量,supplierSkipInbound 契约测试不受影响)。
回归:supplierSkipInbound 12/12 ✅、independentInbound 16/16 ✅、隔离性 10/10 ✅;
全量 25 个失败文件与基线一致(0 新增失败);两端 tsc ✅。
真库交叉验证的**限制**(如实记):
· 录单**不接收明细上的厂商**(`customerOrderSubmitService` 无 supplier_code 入参,分配按
`supplier_categories` 绑定决定),而 BR003 的厂商与分类绑定都是空的 ⇒
「进货单 + 厂商」这条真链**目前构造不出来**,我用临时厂商夹具验证时备货行为 0、待验为 0
(货走了自采)。要真验"厂商进货 + 应付厂商 + 强制入库",需要先有 1 个厂商 + 1 条分类绑定。
· 顺带证实普通客户闸门未被影响:同批实验里普通客户单因"明细售价为 0"被正常拦下(预期行为)。
This commit is contained in:
@@ -49,6 +49,20 @@
|
||||
| 拣货任务生成/修复 | `pickingService.syncMissingPickingTasks`、`repairMissingWarehousePickingForOrder` | 候选查询排除哨兵单 |
|
||||
| 配送任务生成 | `orderWorkflowFulfillmentService.tryAdvanceOrderToDelivering` / `finalizeOrderFulfillment` 的入口 | 哨兵单不从 50/60 走,且入口显式挡一层(防御) |
|
||||
|
||||
### 4.1 入库优先级(开发者 2026-10-12 裁决)
|
||||
|
||||
> 「基本上不会存在免入库的厂商;如果是真设置了、但他这是**独立进货**的,那么就得**走入库**才行 ——
|
||||
> 这个优先级高一些;其他客户下单还是该免入库的免入库。」
|
||||
|
||||
| 订单类型 | 免入库厂商 / 商品直送 | 入库 |
|
||||
|---|---|---|
|
||||
| **独立进货** | **忽略**(一律按"必须入库"处理) | 建待验 + 验收合格入库 ⇒ 齐套后结案 90 |
|
||||
| 普通客户 | 照旧生效 | 该免入库就免入库、该直送就直送 |
|
||||
|
||||
落点:`preparationFulfillmentService.ensureInspectionsForOrder`(哨兵单不吃"跳过建待验"的两个集合)
|
||||
与 `tryAdvanceOrderToInspection` 的 `need_inbound_count`(哨兵单把免入库/直送谓词换成 TRUE)。
|
||||
`ensureSkipInboundLoadingLines` 对哨兵单直接返回(不补核货/拣货行)。
|
||||
|
||||
## 5. 结算口径(**供应商结算不动**)
|
||||
|
||||
| 结算 | 处置 | 落点 |
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { PoolClient } from 'pg';
|
||||
import { isOrderIndependentInbound } from './independentInbound';
|
||||
import { pool } from '../db';
|
||||
import { lookupInspectionItemName } from './inspectionDisplayService';
|
||||
import {
|
||||
@@ -388,15 +389,26 @@ export async function ensureInspectionsForOrder(
|
||||
);
|
||||
|
||||
let created = 0;
|
||||
const skipInboundSuppliers = await loadSkipInboundSupplierSet(
|
||||
preps.rows.map((row) => row.supplier_code),
|
||||
db
|
||||
);
|
||||
const skipDirectSkus = await loadDirectDeliverySkuSetForOrder(
|
||||
orderCode,
|
||||
preps.rows.map((row) => row.sku_code),
|
||||
db
|
||||
);
|
||||
/**
|
||||
* 「独立进货」单(哨兵客户,2026-10-12 开发者裁决)**优先级更高:必须走入库** ——
|
||||
* 即使该厂商被标了「免入库」、或该商品是「商品直送」,也不跳过建待验;
|
||||
* 普通客户单照旧:该免入库就免入库、该直送就直送(下面两个集合原样生效)。
|
||||
* 见 docs/design/20261012-独立进货(自用哨兵客户).md §4
|
||||
*/
|
||||
const independentInboundOrder = await isOrderIndependentInbound(orderCode, db);
|
||||
const skipInboundSuppliers = independentInboundOrder
|
||||
? new Set<string>()
|
||||
: await loadSkipInboundSupplierSet(
|
||||
preps.rows.map((row) => row.supplier_code),
|
||||
db
|
||||
);
|
||||
const skipDirectSkus = independentInboundOrder
|
||||
? new Set<string>()
|
||||
: await loadDirectDeliverySkuSetForOrder(
|
||||
orderCode,
|
||||
preps.rows.map((row) => row.sku_code),
|
||||
db
|
||||
);
|
||||
for (const prep of preps.rows) {
|
||||
// 未完成备货不进待验入库列表(与供应商确认开关无关)
|
||||
if ((Number(prep.prepare_status) || 0) < 30) {
|
||||
@@ -733,6 +745,15 @@ export async function tryAdvanceOrderToInspection(
|
||||
const created = await ensureInspectionsForOrder(orderCode, order.branch_code || null, {
|
||||
client,
|
||||
});
|
||||
const independentInboundOrder = await isOrderIndependentInbound(orderCode, db);
|
||||
/**
|
||||
* 「必须入库」覆盖条件:普通单**原样**(免入库/直送的行不算缺口);
|
||||
* 独立进货单**忽略**这两条(开发者 2026-10-12 裁决:进货单优先级更高,必须走入库)。
|
||||
*/
|
||||
const inboundCoverageFilters = independentInboundOrder
|
||||
? ''
|
||||
: `AND NOT ${supplierSkipInboundExistsSql('oi.supplier_code')}
|
||||
AND NOT ${skuDirectDeliveryAppliesSql('oi.sku_code', 'oi.order_code')}`;
|
||||
const coverage = await db.query(
|
||||
`SELECT
|
||||
(SELECT COUNT(*)::int FROM order_items WHERE order_code = $1) AS item_count,
|
||||
@@ -740,8 +761,8 @@ export async function tryAdvanceOrderToInspection(
|
||||
FROM order_items oi
|
||||
WHERE oi.order_code = $1
|
||||
AND GREATEST(0, COALESCE(oi.quantity, 0) - COALESCE(oi.stock_cover_qty, 0)) > 1e-9
|
||||
AND NOT ${supplierSkipInboundExistsSql('oi.supplier_code')}
|
||||
AND NOT ${skuDirectDeliveryAppliesSql('oi.sku_code', 'oi.order_code')}
|
||||
-- 独立进货单:必须入库(忽略免入库/直送);普通单保持原谓词
|
||||
${inboundCoverageFilters}
|
||||
) AS need_inbound_count,
|
||||
-- 非商品直送的行数:这些行的货**必须经我们仓库出库**(含"库存抵扣"的行——它们没有缺口,
|
||||
-- 但货在我们仓里,仍需分拣出库+配送)。见 docs/design/20261009-供应商侧库存抵扣与免入库推进方案.md
|
||||
|
||||
@@ -99,6 +99,34 @@ describe('② 全部入库 ⇒ 直接完成(90),且绝不被推到待配
|
||||
});
|
||||
});
|
||||
|
||||
describe('②b 入库优先级(开发者裁决):独立进货必须入库,普通单照旧', () => {
|
||||
const prep = svc('src/services/preparationFulfillmentService.ts');
|
||||
|
||||
it('建待验:哨兵单忽略"免入库厂商/商品直送"两个跳过集合', () => {
|
||||
const idx = prep.indexOf('export async function ensureInspectionsForOrder');
|
||||
const body = prep.slice(idx, idx + 3000);
|
||||
expect(body).toContain('const independentInboundOrder = await isOrderIndependentInbound(orderCode, db)');
|
||||
expect(body).toMatch(/independentInboundOrder\s*\?\s*new Set<string>\(\)\s*:\s*await loadSkipInboundSupplierSet\(/);
|
||||
expect(body).toMatch(/independentInboundOrder\s*\?\s*new Set<string>\(\)\s*:\s*await loadDirectDeliverySkuSetForOrder\(/);
|
||||
// 普通单仍走原来的两个集合
|
||||
expect(body).toContain('loadSkipInboundSupplierSet(');
|
||||
expect(body).toContain('loadDirectDeliverySkuSetForOrder(');
|
||||
});
|
||||
|
||||
it('30→40 覆盖判定:哨兵单不吃"免入库/直送"两条过滤,普通单原样', () => {
|
||||
const idx = prep.indexOf('const independentInboundOrder = await isOrderIndependentInbound(orderCode, db);', prep.indexOf('export async function tryAdvanceOrderToInspection'));
|
||||
expect(idx).toBeGreaterThan(-1);
|
||||
const body = prep.slice(idx, idx + 3500);
|
||||
// 哨兵单:条件整体为空 ⇒ 该行必须靠验收覆盖才能算齐套
|
||||
expect(body).toMatch(/const inboundCoverageFilters = independentInboundOrder\s*\n?\s*\? ''/);
|
||||
// 普通单:原样两条过滤(另有 supplierSkipInbound 契约测试钉住字面量)
|
||||
expect(body).toContain("AND NOT ${supplierSkipInboundExistsSql('oi.supplier_code')}");
|
||||
expect(body).toContain("AND NOT ${skuDirectDeliveryAppliesSql('oi.sku_code', 'oi.order_code')}");
|
||||
// 覆盖判定 SQL 里用的是这个 fragment
|
||||
expect(body).toContain('${inboundCoverageFilters}');
|
||||
});
|
||||
});
|
||||
|
||||
describe('③ 结算:供应商结算不动,客户结算不生成', () => {
|
||||
it('客户结算入口(唯一实现)对哨兵单直接 skipped', () => {
|
||||
const idx = finance.indexOf('async function runUpsertCustomerStatementForOrder');
|
||||
|
||||
Reference in New Issue
Block a user