Files
SupplierSystem/server/tests/selfPurchaseActualQtyWriteback.test.ts
T
Ubuntu aa2db57b0f
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(main-system): 免入库单取货链路 + 实收数量「事实登记 + 事后同步」
免入库(主系统骑手上门取货):
- 50 展示「待取货」、副文案「待主系统骑手上门取货」、不建我方配送任务(守卫与开关解耦)
- 我方 50 即回写备货完成;两开关(SKIP_INBOUND_AWAIT_PICKUP / FULFILLMENT_EVENTS)改默认开

核货事实镜像(「核货完毕」标记):
- 按主系统 lookup 的 actual_qty 落台账,新增 GET/POST /orders/:orderCode/main-system-prep-facts[/refresh]
- 详情行内显示「核货完毕」(含核货量),分配对账兜底刷新

实收数量/单位口径变更(对方先改 + 我方事后同步):
- 台账加 applied_at;inbound 与 picking_check 同为事实登记(驳回不回滚)
- 同意才落我方值:免入库改装车核货量、送仓改验收实收(已入库走既有库存调整)、已结算/已结案只留痕
- 计划量与金额一起改,并同步结算投影(syncStatementsForOrderSafe)
- 审核页语义改「主系统实际值(已生效)/ 是否同步」+ 已处理历史(双方时间与落值结论)

台账对照与回写修复:
- 行级对照改整单一次性(同名商品不再重复认领)+ 存量纠正 healOrderPrepMapping
- 堵住客户绑定回填旁路(免入库单不再被派我方骑手)
- 回写触发函数改对象参数(修 branch/order 传反导致的静默不回写)

文档:设计文档 4 篇 +《给主系统 AI 的对接改造清单》§2.9(第六批契约)

回归:服务端全量与 HEAD 基线一致(24 个失败文件同集合);前端 140 文件 / 699 测试全绿;tsc 双端干净
2026-10-09 21:52:17 +08:00

47 lines
2.3 KiB
TypeScript

import { readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
/**
* §8.7 自采入库实收回写订单(开发者 2026-10-11 定稿)。
*
* 事故:订单 `…SUP37831443_0002` 的「八角」自采入库录 0.6,订单详情仍显示 0.5(= 计划量)。
* 根因:详情页「实收数量」读 `inspections.actual_qty`(其次 `picking_items.loaded_qty`),
* 而自采入库写的是第三张表 `self_purchase_stock_inbounds`,两者无关联。
* 口径:入库成功后经 `inspection_id → inspections.order_item_id` **唯一定位**订单行,
* 把该验收记录的 `actual_qty` 更新为入库数量;定位不到 ⇒ 跳过并记日志(不猜)。
*/
const src = readFileSync(
new URL('../src/services/selfPurchaseStockInboundService.ts', import.meta.url),
'utf8'
);
const fn = src.slice(
src.indexOf('export async function createSelfPurchaseStockInbound'),
src.indexOf('void writeAuditLog', src.indexOf('export async function createSelfPurchaseStockInbound'))
);
describe('自采入库 → 订单实收回写', () => {
it('经 inspection_id 唯一定位订单行后回写 inspections.actual_qty', () => {
expect(fn).toContain('SELECT order_item_id FROM inspections WHERE id = $1::uuid');
expect(fn).toContain('UPDATE inspections SET actual_qty = $2 WHERE id = $1::uuid');
expect(fn).toContain('actualQtyWrittenBack = true');
});
it('回写必须晚于入库 INSERT、且在同一次 COMMIT 之前(同一事务)', () => {
const insertIdx = fn.indexOf('INSERT INTO self_purchase_stock_inbounds');
const wbIdx = fn.indexOf('UPDATE inspections SET actual_qty');
// 取**回写之后**的那次 COMMIT(函数里前面还有别的提交点)
const commitIdx = fn.indexOf("if (owns) await client.query('COMMIT')", wbIdx);
expect(insertIdx).toBeGreaterThan(-1);
expect(wbIdx).toBeGreaterThan(insertIdx);
expect(commitIdx).toBeGreaterThan(wbIdx);
});
it('定位不到订单行 ⇒ 跳过 + 记日志(独立/称台入库不回写)', () => {
expect(fn).toContain('未关联订单行(独立/称台入库),本次不回写订单实收');
});
it('回写失败不阻断入库', () => {
expect(fn).toContain('订单实收回写失败(不影响入库)');
});
});