开发者 2026-10-17:「从配送系统传过来的单子也能删除」——覆盖 2026-10-10 的「主系统单禁删」。 口径: · 删行(上一轮已放开)与**删单**现在都允许;「缺货」按钮保留(那是报给主系统的正规通道)。 · 删单走既有两条路(移入垃圾桶 / 垃圾桶彻底删除),删前**同一事务**把该单涉及的 行级台账(public.main_system_order_import_items)全部置 disposition='cancelled': 按 our_order_code 反查,并兼容明细已被清空的情况(our_order_item_id IN (SELECT id FROM order_items…))。 · 不落账的后果:导入每轮按台账重算"哪些行还要追加/建单" ⇒ 删掉的单会在下一轮原样复活。 置 cancelled 后 needsAppendToOrder 返回 false,且台账 upsert 的处置是粘性的。 · 从垃圾桶恢复无需撤销处置:恢复后行上仍有 our_order_item_id 对照 ⇒ 不会重复建行。 · **不回写主系统**(对方没有"供应商删单"接口);因此"供不了"仍应优先用「缺货」, 删单只用于"这单本来就不该进"(如主系统重复派单)。 改动: · orderDeleteService:删除 assertNotMainSystemOrder,新增 suppressMainSystemPrepRowsForOrder(), 在 moveOrderToTrash() 与 deleteOrderWithDependencies() 两处调用。 · 订单列表:删除按钮不再排除主系统单(仅保留权限判断),沿用既有确认弹窗与文案(未新增文案)。 · 测试:mainSystemItemDeletable 更新为"整单可删 + 两条删路都落账 + 处置幂等",12 条全过。 验证: · npm run typecheck → 0 错;cd server && npx tsc --noEmit → 0 错 · 前端 order 相关 42 文件 / 245 用例全过;后端 orderDelete + mainSystem 30 文件 / 468 用例全过 · 设计门禁:8 通过 / 1 已知红 check-ai-cost / verify-facts 因本地缺 tenant_br003 红(均基线)
134 lines
5.7 KiB
TypeScript
134 lines
5.7 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
||
import path from 'node:path';
|
||
import { describe, expect, it } from 'vitest';
|
||
import { needsAppendToOrder } from '../src/services/mainSystemOrderImport';
|
||
|
||
/**
|
||
* 主系统同步过来的商品行:**允许删除**(开发者 2026-10-17 裁决,覆盖 2026-10-10 的"禁删")。
|
||
*
|
||
* 三条必须同时成立,缺一条就会变成灾难:
|
||
* ① 服务层不再对主系统单抛 409 `main_system_item_locked`(否则界面给了按钮也点不动);
|
||
* ② 删除**同一事务**里把该行的主系统台账处置成 `cancelled`(否则下一轮对账/webhook 追加把它塞回来,
|
||
* 用户会看到"删了又回来");
|
||
* ③ **删单仍然禁止**(`orderDeleteService.assertNotMainSystemOrder` 不许动)——
|
||
* 删行和删单是两件事,后者会扯断退货红冲/发车回写的对照。
|
||
*/
|
||
const itemsService = readFileSync(
|
||
path.join(__dirname, '../src/services/orderManageItemsService.ts'),
|
||
'utf8'
|
||
);
|
||
const deleteService = readFileSync(
|
||
path.join(__dirname, '../src/services/orderDeleteService.ts'),
|
||
'utf8'
|
||
);
|
||
const ledgerService = readFileSync(
|
||
path.join(__dirname, '../src/services/mainSystemPrepLedger.ts'),
|
||
'utf8'
|
||
);
|
||
const panel = readFileSync(
|
||
path.join(__dirname, '../../src/components/order/OrderDetailDeliveryNotePanel.tsx'),
|
||
'utf8'
|
||
);
|
||
|
||
describe('① 服务层:主系统行不再被 409 拦住', () => {
|
||
it('已经不再抛 main_system_item_locked', () => {
|
||
expect(itemsService).not.toMatch(/main_system_item_locked/);
|
||
expect(itemsService).not.toMatch(/主系统分配过来的商品不能删除/);
|
||
});
|
||
|
||
it('删除时把该行台账置 cancelled(且与删除同事务:传 client)', () => {
|
||
const idx = itemsService.indexOf('SELECT prep_id FROM public.main_system_order_import_items');
|
||
expect(idx).toBeGreaterThan(-1);
|
||
const block = itemsService.slice(idx, idx + 900);
|
||
expect(block).toMatch(/disposition: 'cancelled'/);
|
||
expect(block).toMatch(/reason: '子系统删除明细(操作员)'/);
|
||
expect(block).toMatch(/client,/);
|
||
});
|
||
|
||
it('markPrepDisposition 支持事务连接(否则处置会落在事务外、删了又复活)', () => {
|
||
expect(ledgerService).toMatch(/client\?: \{ query:/);
|
||
expect(ledgerService).toMatch(/params\.client \|\| pool/);
|
||
});
|
||
|
||
it('台账处置失败不阻断删除(只记日志,巡检兜底)', () => {
|
||
const idx = itemsService.indexOf('主系统行处置落账失败');
|
||
expect(idx).toBeGreaterThan(-1);
|
||
expect(itemsService.slice(Math.max(0, idx - 400), idx)).toMatch(/catch/);
|
||
});
|
||
});
|
||
|
||
describe('② 防复发:cancelled 的行不会被追加回来', () => {
|
||
it('needsAppendToOrder 对 cancelled 说"不用追加"', () => {
|
||
expect(
|
||
needsAppendToOrder({ id: 'prep-1' }, [
|
||
{ prep_id: 'prep-1', our_order_item_id: null, disposition: 'cancelled' },
|
||
])
|
||
).toBe(false);
|
||
});
|
||
|
||
it('与之对照:imported + 空链接仍然要补(既有修复不许被这次改动削弱)', () => {
|
||
expect(
|
||
needsAppendToOrder({ id: 'prep-1' }, [
|
||
{ prep_id: 'prep-1', our_order_item_id: null, disposition: 'imported' },
|
||
])
|
||
).toBe(true);
|
||
});
|
||
|
||
it('已配上订单行的行不会被重复追加', () => {
|
||
expect(
|
||
needsAppendToOrder({ id: 'prep-1' }, [
|
||
{ prep_id: 'prep-1', our_order_item_id: 'item-1', disposition: 'imported' },
|
||
])
|
||
).toBe(false);
|
||
});
|
||
});
|
||
|
||
describe('③ 整单删除:允许,但要先把台账处置掉(否则下一轮导入复活)', () => {
|
||
it('不再有"主系统单禁删"的断言与错误码', () => {
|
||
expect(deleteService).not.toMatch(/assertNotMainSystemOrder/);
|
||
expect(deleteService).not.toMatch(/main_system_order_locked/);
|
||
});
|
||
|
||
it('两条删路(移入垃圾桶 / 彻底删除)都调用同一处置函数', () => {
|
||
const calls = deleteService.match(/suppressMainSystemPrepRowsForOrder\(client, code\)/g) || [];
|
||
expect(calls.length).toBeGreaterThanOrEqual(2);
|
||
});
|
||
|
||
it('处置按整单写:our_order_code 反查 + 兼容明细已清空 + 只写非 cancelled 行(幂等)', () => {
|
||
const idx = deleteService.indexOf('async function suppressMainSystemPrepRowsForOrder');
|
||
expect(idx).toBeGreaterThan(-1);
|
||
const block = deleteService.slice(idx, idx + 1200);
|
||
expect(block).toMatch(/UPDATE public\.main_system_order_import_items/);
|
||
expect(block).toMatch(/our_order_code = \$1/);
|
||
expect(block).toMatch(/our_order_item_id IN \(SELECT id FROM order_items WHERE order_code = \$1\)/);
|
||
expect(block).toMatch(/disposition = 'cancelled'/);
|
||
expect(block).toMatch(/COALESCE\(disposition, ''\) <> 'cancelled'/);
|
||
});
|
||
});
|
||
|
||
describe('④ 界面:主系统行也有删除入口(无新增文案)', () => {
|
||
it('isMainSystemOrder 分支里出现 onRemoveItem,且沿用既有 title 文案键', () => {
|
||
const branchStart = panel.indexOf('{isMainSystemOrder ? (');
|
||
expect(branchStart).toBeGreaterThan(-1);
|
||
// 取主系统分支到非主系统分支之间的片段
|
||
const branchEnd = panel.indexOf(') : (', branchStart);
|
||
expect(branchEnd).toBeGreaterThan(branchStart);
|
||
const block = panel.slice(branchStart, branchEnd);
|
||
expect(block).toMatch(/onRemoveItem\(item\)/);
|
||
expect(block).toMatch(/t\('orders\.detail\.hintDelete'\)/);
|
||
expect(block).toMatch(/t\('orders\.detail\.hintKeepOne'\)/);
|
||
});
|
||
});
|
||
|
||
describe('⑤ 界面:订单列表的删除按钮不再排除主系统单', () => {
|
||
const page = readFileSync(
|
||
path.join(__dirname, '../../src/pages/orders/orderManagement/OrderManagementPage.tsx'),
|
||
'utf8'
|
||
);
|
||
|
||
it('删除按钮的显示条件只剩权限(不再 && !is_main_system_order)', () => {
|
||
expect(page).toMatch(/canDeleteOrder && \(/);
|
||
expect(page).not.toMatch(/canDeleteOrder && !o\.is_main_system_order/);
|
||
});
|
||
});
|