Files
SupplierSystem/server/tests/processingPickRespectReservations.test.ts
T
雨天andUbuntu 29fbf49481
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
feat(多模块): 代提交另一会话遗留在工作区的整批改动(内容零修改)
原改动人:雨天 <oncwnuHbbvAwYZMdPF78PsWNPadI@git.weixin.qq.com>
代为提交:Lead 会话(本 commit 内容与该会话工作区逐字节一致,未做任何修改),
目的是不让在研成果丢失、并让工作树回到干净可部署状态。

提交前由 Lead 实跑验证:
- 前端 npx tsc --noEmit 0 错误;后端 server npx tsc --noEmit 0 错误
- 本批新增的 7 个测试 54/54 通过;Lead 侧契约测试(散客录单/文案/成本列)42/42 通过
- bash tools/design-consistency/run-all.sh --verify:通过 8 / 未通过 1(check-ai-cost,既有红)/ 未执行 1(verify-facts,本地库不可连)—— 与基线一致

新增能力(各含 docs/design 设计文):
- 独立进货不得有配送任务:生成侧兜底 + 补建候选 + 查询侧三道防线(实测 5 张独立进货单里 4 张有僵尸 delivery_tasks)
- 主系统追加行零价闸门尊重其已声明的 allowUnpriced(否则整批分配行静默丢失)
- 库存抵扣为 0 的原因可见(不再静默,原因判定与抵扣量同源并落到日志与「库存抵扣」入口)
- 退货/删单跟随改独立 2 分钟周期(MAIN_SYSTEM_RETURN_FOLLOW_SEC,置 0 退回旧行为)
- 加工领料可用本单自己的预留(放行必须与本单预留消费成对,避免短送与同一批算两次)
- 出库拍照预览、主系统实收 / SKU 映射 / 单位变更 inbox 等配套

同一批包含对已废弃旧方案的回滚(design doc 与 README 索引行一并移除):
- 独立进货建客户档案(方案甲)→ 回到哨兵方案;随之删除 migrations/20261044_independent_inbound_customer.sql
- 分类新建去重(同名复用已有)
- 分拣标签纸张尺寸预设 / 分拣标签可选客户名与区域

未包含:src/pages/orders/OrderManagementPage.tsx(0 字节空文件,疑似误建,既未提交也未删除)
2026-10-15 11:29:15 +08:00

80 lines
4.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
/**
* 仓内加工领料必须扣除库存预留(2026-09-22 开发者实测报告)。
*
* 现象:需求单领料弹窗把**已被预留占用**的货显示成"可用"并能真的领走
* (BR004 实测:前夹精瘦肉 显示 15 / 真实可领 0;抄手皮 显示 16.2 / 真实可领 8.2)。
* 根因:候选列表用毛可用;三处领料校验也用毛可用,且扣减显式 `respectOtherReservations: false`
* 关掉了预留保护(与分拣/发车路径、与 getClaimableStockQty 口径不一致)。
* 见 docs/design/20260922-processing-pick-respect-reservations.md
*/
const read = (rel: string) => readFileSync(new URL(`../src/${rel}`, import.meta.url), 'utf8');
describe('仓内加工领料:预留口径', () => {
const standalone = read('services/processingStandaloneService.ts');
const demand = read('services/processingDemandSheetService.ts');
const amend = read('services/processingDemandPickAmendService.ts');
it('候选列表的"可用"必须减去在用预留(status=10)', () => {
expect(standalone).toContain('FROM inventory_reservations r');
expect(standalone).toContain('r.status = 10');
expect(standalone).toContain('GREATEST(0,');
expect(standalone).toContain('reserved_qty');
// 不再直接把毛可用当"可用"
expect(standalone).not.toContain('COALESCE(SUM(inv.available_qty), 0)::float AS available_qty');
});
/**
* 2026-10-14 开发者批准后的口径(**取代**本文件原先的"三处一律扣全部在用预留"):
* · **需求单领料**(`processingDemandSheetService` / `processingDemandPickAmendService`):
* 可领 = 毛可用 − **他单**预留 —— 本单成品就是本单已预留的那批货,本单预留不该挡自己;
* 且扣库后**必须成对**消费本单预留(否则"库存已扣、预留仍在"⇒ 短送 + 同一批算两次);
* · **独立加工领料**(`processingStandaloneService`,无需求单):维持"扣全部在用预留"。
* 见 docs/design/20261014-加工领料可用本单预留.md
*/
it('需求单领料:可领 = 毛可用 − 他单预留,且领料后消费本单预留', () => {
for (const [name, src] of [
['processingDemandSheetService', demand],
['processingDemandPickAmendService', amend],
] as const) {
expect(src, name).toContain('sumAvailableQty');
expect(src, name).toContain('sumOtherOrderReservations');
expect(src, name).toContain('claimOwnOrderReservationForProcessingPick');
expect(src, name).toContain('orderCode: ownOrderCodes[0] || null');
// 不得再回退成"扣全部在用预留"
expect(src, name).not.toContain('getClaimableStockQty(client, skuCode, branchCode, null)');
expect(src, name).not.toContain('getClaimableStockQty(client, skuCode, input.branchCode, null)');
}
});
it('独立加工领料(无需求单)维持旧口径:扣全部在用预留', () => {
expect(standalone).toContain('getClaimableStockQty(client, skuCode, branchCode, null)');
expect(standalone).toContain("from './inventoryStockCoverService'");
});
it('任何领料路径都不得关掉 FIFO 的预留守卫', () => {
for (const [name, src] of [
['processingDemandSheetService', demand],
['processingDemandPickAmendService', amend],
['processingStandaloneService', standalone],
] as const) {
expect(src, name).not.toContain('respectOtherReservations: false');
}
});
it('分拣/发车路径的显式守卫保持开启(本改动不碰)', () => {
const outbound = read('services/inventoryOutboundService.ts');
expect(outbound).toContain('respectOtherReservations: true');
expect(outbound).toContain('默认 true:扣库不得超过「毛可用−他单预留」');
});
it('保留可复跑的口径审计入口', () => {
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')) as {
scripts: Record<string, string>;
};
expect(pkg.scripts['audit:stock-claimable']).toContain('scripts/audit-stock-claimable.ts');
});
});