Files
SupplierSystem/server/tests/purchaseAmendCostWriteback.test.ts
T
雨天 5e60fa5226
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(库存/订单/采购): 可见性、订单详情交互与成本回写
- 库存列表:新增「未设成本价」可见性(筛选 + KPI「缺成本价批次」 +
  成本价列红字「未设置」),纯只读,不碰 cost_details 台账
- 库存列表:新增「总价值」列(可用数量×成本价),隐藏「产地」列
- 订单列表/详情:独立进货单客户名回退显示「独立进货」
- 订单详情:独立进货单隐藏「销售价」列(不可设置)
- 订单详情:分类下拉支持直接新建分类(与商品选择框同款常驻入口)
- 采购:自采改价 → 订单行成本回写与「有无实收」解耦,修「改完自采价、
  采购备货风险提示仍按订单行旧值报警」

设计:docs/design/20261014-*.md;
20260922-order-cost-writeback-to-supply.md §2026-10-14 修订
2026-10-13 16:00:36 +08:00

60 lines
2.7 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 path from 'node:path';
import { describe, expect, it } from 'vitest';
/**
* 自采改价 → **订单行成本回写**与「有无实收」解耦(2026-10-14 方案 A,开发者批准)。
*
* 现象:自采价改成 1.9,但「采购备货风险提示」仍显示 4、继续报 —— 因为风险成本取
* `GREATEST(自采价, order_items.unit_cost)`,而订单行成本没跟着变。
* 根因:`amendPurchaseActual` 的「回写订单行成本」整段写在 `if (beforeQty > 0 …)` 里;
* 自采 UI 路由恒传 `preserveActualQty: true`,未验收(`actual_qty IS NULL`)时 `beforeQty`
* 退化成 0 ⇒ 整段跳过。
*
* 本文件钉住三条不变量(源码级,防回退):
* ① 成本回写**不在** `beforeQty > 0` 分支里(已移出);
* ② 解耦条件 = `beforeQty > 0 || 价格确实变了`;
* ③ 「数量/履约」同步仍由 `beforeQty > 0` 把关(方案 C 不变)。
*
* 设计:docs/design/20260922-order-cost-writeback-to-supply.md(2026-10-14 修订)
*/
const svc = readFileSync(
path.join(__dirname, '../src/services/purchaseAmendService.ts'),
'utf8'
);
const routes = readFileSync(
path.join(__dirname, '../src/modules/workflow/routes/purchaseRoutes.ts'),
'utf8'
);
describe('自采改价:订单行成本回写与「有无实收」解耦', () => {
it('① 成本回写已移出 `beforeQty > 0` 分支(排在 else-if 数量/单位分支之后)', () => {
const unitOnlyBranch = svc.indexOf(
"else if (!input.skipOrderItemSync && nextUnit !== beforeUnit"
);
const costWriteback = svc.indexOf("await import('./orderItemUnitCostService')");
expect(unitOnlyBranch).toBeGreaterThan(-1);
expect(costWriteback).toBeGreaterThan(-1);
// 成本回写在 unit-only 分支之后 ⇒ 不再受 beforeQty 独占分支约束
expect(costWriteback).toBeGreaterThan(unitOnlyBranch);
});
it('② 解耦条件:`beforeQty > 0 || 价格确实变了`', () => {
expect(svc).toContain('(beforeQty > 0 || Math.abs(nextPrice - beforePrice) > 1e-9)');
// 既有守卫不变
expect(svc).toContain('!input.skipOrderItemSync &&');
expect(svc).toContain('!input.preserveOrderEnteredCost &&');
});
it('③ 数量/履约同步仍由 beforeQty>0 把关(方案 C 不变)', () => {
expect(svc).toContain(
'if (beforeQty > 0 && row.order_code && row.sku_code && !input.skipOrderItemSync) {'
);
expect(svc).toContain('syncOrderItemsFromSupplyCompletion');
});
it('④ 自采路由仍恒传 preserveActualQty=true(记录导致改前漏回写的约束)', () => {
expect(routes).toContain('preserveActualQty: true');
});
});