Files
SupplierSystem/server/tests/mainSystemQtyLock.test.ts
T
Ubuntu f27438fafe
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
fix(分配单锁定): 配送时间 / 加工方式(含加工方)也只能主系统改 —— 三道门 + 真库实测
开发者口径(原话要点):「分配来的订单不能修改配送时间,还有下方的加工方式的选择 ——
只能是主系统那边改了我们这边同步才行。」

三个字段(数量 / 配送时间 / 加工方式+加工方)在主系统分配行上全部只读,每项都是三道门:

  服务层(第二道门,接口级)orderManageItemsService.ts:
    · 配送时间 updateOrderDeliveryDate ⇒ 409 main_system_delivery_date_locked
      (判据:整单存在主系统分配行 = 行级 main_order_code;拦在状态闸门之前)
    · 加工方式/加工方 ⇒ 409 main_system_processing_locked
      (新增 collectMainSystemProcessingChanges:与价格数量**分开**一条列表 —— 加工方式不通知主系统,直接拒绝)
  界面(第一道门):
    · 订单列表行内改配送日:准入加 `is_main_system_order !== true`,双击退回"打开详情",title 给提示
    · 详情面板:加工方式下拉与加工方按钮在 `rowEditable && !planQtyLocked` 时才渲染,否则渲染文本 + title
  小程序 order-manage-detail:
    · 日期 picker `disabled="{{isMainSystemOrder}}"`(data 根上按"服务端标记 or 行上有 main_order_code"兜底判)
    · 加工方式 picker / 加工方 chips 置灰 + 点它 toast
文案(已批准,三语):分发订单的配送时间无法修改(以主系统为准)/ 分发订单的加工方式无法修改(以主系统为准)

⚠️ 真库实测抓到自己一个真 bug(已修,测试钉住):加工方式守卫起初写在 `if (changes.length)`
(价格/数量有改动)分支内 ⇒ **只改加工方式**时整段被跳过、改动直接落库,门形同虚设。
现在并集判定 `if (changes.length || processingChanges.length)`。

实测(真库):
  · 配送时间:ORD_API_20261010_BR003_0001 改 10-11→10-12 ⇒ 409 + 批准文案,库值未变
  · 加工方式:同一单「精瘦肉」原材料→去皮(价量均未动)⇒ 409 main_system_processing_locked,库值仍为 原材料
  · 服务端 2352 用例 / 失败文件 25 = 基线 24 + 另一条工作线遗留的 zeroCostClearsPlanPrice(非本次引入)
  · 前端 717 用例(+3 新增),失败仅 SystemConfig.allowZeroCost 2 条(同属另一条工作线的 StockInboundPanel 重写)

设计记录:docs/design/20261011-跨系统改价改量审核.md §10.5.1
2026-10-10 19:21:54 +08:00

123 lines
6.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 { describe, expect, it } from 'vitest';
/**
* 主系统分配行的**数量不可改**(开发者 2026-10-10 口径):
* 「主系统给子系统的订单,这个**计划数量**取消可以编辑的权限(子系统正常录单的不要被影响)」。
*
* 三道门(缺一不可):
* ① 界面(Web 订单明细):计划数量渲染成文本 —— `orderDetailPlanQtyLock.test.ts`;
* ② 服务层(改明细 5 个入口共用):主系统分配行的 `quantity` 改动 **409 直接拒绝**(本文件);
* ③ 小程序(订单管理端 + 采购员端):明细接口带 `main_order_code`、数量格置灰不进编辑弹窗。
*
* 只锁**数量**:价格仍走「先改后通知」(2026-10-12 口径);我方自建行(加菜/自录)完全不受影响。
*/
const service = readFileSync(
new URL('../src/services/orderManageItemsService.ts', import.meta.url),
'utf8'
);
const mobileAdmin = readFileSync(
new URL('../src/routes/mobile/mobileAdminRoutes.ts', import.meta.url),
'utf8'
);
const mobilePurchaser = readFileSync(
new URL('../src/routes/mobile/mobilePurchaserOrderRoutes.ts', import.meta.url),
'utf8'
);
const mpJs = readFileSync(
new URL('../../miniprogram/pages/order-manage-detail/order-manage-detail.js', import.meta.url),
'utf8'
);
const mpWxml = readFileSync(
new URL('../../miniprogram/pages/order-manage-detail/order-manage-detail.wxml', import.meta.url),
'utf8'
);
describe('服务层:加工方式 / 配送时间同样锁(2026-10-10 口径)', () => {
it('加工方式/加工方改动 ⇒ 409 main_system_processing_locked,文案已批准', () => {
const idx = service.indexOf('const processingLocked = guardedProcessingChanges;');
expect(idx, '未找到加工方式拦住逻辑').toBeGreaterThan(-1);
const body = service.slice(idx, idx + 600);
expect(body).toContain("code: 'main_system_processing_locked'");
expect(body).toContain('分发订单的加工方式无法修改(以主系统为准)');
// 必须与价格/数量的列表分开:加工方式**不通知主系统**,直接拒绝(混进去会误发通知)
expect(service).toContain('collectMainSystemProcessingChanges');
expect(service).toContain('const guardedProcessingChanges = processingChanges.filter(');
/**
* ⚠️ 必须与价格/数量的判定**并集**(`if (changes.length || processingChanges.length)`):
* 真库实测踩到过一次 —— 起初它写在 `if (changes.length)` 里,
* **只改加工方式**(价格数量没动)时整段被跳过、改动直接落库,门形同虚设。
*/
expect(service).toContain('if (changes.length || processingChanges.length) {');
// 判据:只比"本次确实传了值且与库里不同",未传=不涉及该字段
const fn = service.slice(
service.indexOf('function collectMainSystemProcessingChanges'),
service.indexOf('function collectMainSystemProcessingChanges') + 2200
);
expect(fn).toContain('nextMethod && nextMethod !== prevMethod');
expect(fn).toContain("field: 'processing_owner'");
});
it('配送时间改动 ⇒ 409 main_system_delivery_date_locked,判据=整单存在主系统分配行', () => {
const idx = service.indexOf('export async function updateOrderDeliveryDate');
expect(idx).toBeGreaterThan(-1);
const body = service.slice(idx, idx + 2600);
expect(body).toContain("code: 'main_system_delivery_date_locked'");
expect(body).toContain('分发订单的配送时间无法修改(以主系统为准)');
expect(body, '判据必须按行 main_order_code(与我方自建单区分)').toContain(
"NULLIF(TRIM(main_order_code), '') IS NOT NULL"
);
// 必须在状态闸门/更新之前拦下
expect(body.indexOf('main_system_delivery_date_locked')).toBeLessThan(
body.indexOf('canEditDeliveryDateByStatus')
);
});
});
describe('服务层:主系统分配行改数量 ⇒ 409(不是"先改后通知")', () => {
it('只拦 quantity、只拦 guarded(主系统分配行),错误码固定', () => {
const idx = service.indexOf("const qtyLocked = guardedChanges.filter");
expect(idx, '未找到数量拦住逻辑').toBeGreaterThan(-1);
const body = service.slice(idx, idx + 1200);
expect(body).toContain("change.field === 'quantity'");
expect(body).toContain("code: 'main_system_qty_locked'");
// 文案与小程序一致(「分发订单的数量无法修改」),便于用户在两处看到同一句话
expect(body).toContain('分发订单的数量无法修改(${names})');
expect(body).toContain('status: 409');
// 抛错在"通知主系统"之前 ⇒ 被拒的改动不会既报错又发通知
const noticeIdx = service.indexOf('priceQtyNotices = guardedChanges;');
expect(noticeIdx).toBeGreaterThan(idx);
});
it('价格不受影响(仍走先改后通知),我方自建行也不在 guarded 里', () => {
const idx = service.indexOf('const guardedChanges = changes.filter');
// 窗口要覆盖"数量拦下 → 加工方式拦下 → 价格放行"整段(2026-10-10 追加了加工方式那道门)
const body = service.slice(idx, idx + 2600);
expect(body).toContain('priceQtyNotices = guardedChanges;');
// 仍然只对 guarded(= isMainSystemAllocatedLines 判定的主系统分配行)生效
expect(body).toContain('guarded.has(change.itemId)');
});
});
describe('小程序:明细接口带 main_order_code,数量格按行锁', () => {
it('订单管理端 / 采购员端明细查询都返回行级来源', () => {
expect(mobileAdmin).toMatch(/oi\.main_order_code/);
expect(mobilePurchaser).toMatch(/oi\.main_order_code/);
});
it('小程序按行判定 planQtyLocked,且点击数量格不进编辑弹窗', () => {
expect(mpJs).toContain('planQtyLocked: Boolean(String(row.main_order_code || \'\').trim())');
// 点击给一句说明(开发者 2026-10-10 定稿文案:「分发订单的数量无法修改」),然后不进编辑弹窗
expect(mpJs).toMatch(/if \(field === 'qty' && item\.planQtyLocked\) \{/);
expect(mpJs).toContain("'分发订单的数量无法修改'");
expect(mpJs).toMatch(/wx\.showToast\(\{ title: '分发订单的数量无法修改', icon: 'none' \}\);/);
// 数量格带置灰样式(不加文案)
expect(mpWxml).toContain("{{item.planQtyLocked ? 'cell-locked' : ''}}");
});
it('我方正常录单不受影响:判据是**行上有 main_order_code**,不是整单标记', () => {
expect(mpJs).not.toMatch(/planQtyLocked: Boolean\([^)]*isMainSystemOrder/);
expect(mpJs).toMatch(/planQtyLocked: Boolean\(String\(row\.main_order_code/);
});
});