From c5dd3bf804311e9c8d5d2612ce7d72bf1a77b65b Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sat, 10 Oct 2026 17:01:32 +0800 Subject: [PATCH] =?UTF-8?q?test(=E5=90=88=E5=B9=B6=E9=94=AE):=20=E9=92=89?= =?UTF-8?q?=E4=BD=8F=E3=80=8C=E5=90=8C=E4=B8=80=E5=A4=A9=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E4=B8=BB=E7=B3=BB=E7=BB=9F=E5=88=86=E5=85=AC=E5=8F=B8=20?= =?UTF-8?q?=E2=87=92=20=E6=8B=86=E4=B8=A4=E5=BC=A0=E5=8D=95=E3=80=8D?= =?UTF-8?q?=EF=BC=882026-10-27=20=E8=A3=81=E5=86=B3=20=C2=A75.1=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 同一天 + 不同主系统分公司 ⇒ 两个桶(不得并单:送达地址不同) - 同一天 + 同一主系统分公司 ⇒ 仍并一张(原口径不回退) - 行里没有主系统分公司 ⇒ 空键(与存量占坑行同口径) 设计:docs/design/20261027-分公司接入编码与主系统供应商绑定.md §5.1 --- .../mainSystemDayMergeAndStockout.test.ts | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/server/tests/mainSystemDayMergeAndStockout.test.ts b/server/tests/mainSystemDayMergeAndStockout.test.ts index 44abc28..9c77da4 100644 --- a/server/tests/mainSystemDayMergeAndStockout.test.ts +++ b/server/tests/mainSystemDayMergeAndStockout.test.ts @@ -92,13 +92,26 @@ function row(over: Record) { } as never; } -function group(orderCode: string, deliveryDate: string | null, names: string[]): MainOrderGroup { +function group( + orderCode: string, + deliveryDate: string | null, + names: string[], + /** 主系统分公司(行的 `branch_code`);不传 = 行里没带(走主系统单号兜底/空键) */ + mainBranchCode?: string +): MainOrderGroup { return { orderCode, deliveryDate, taskDay: deliveryDate, rows: names.map((itemName, index) => - row({ id: `${orderCode}-${index}`, orderCode, itemName, deliveryDate, prepareQty: index + 1 }) + row({ + id: `${orderCode}-${index}`, + orderCode, + itemName, + deliveryDate, + prepareQty: index + 1, + ...(mainBranchCode ? { branchCode: mainBranchCode } : {}), + }) ), } as MainOrderGroup; } @@ -119,6 +132,45 @@ describe('按配送日合并', () => { expect(buckets[1].groups.map((g) => g.orderCode)).toEqual(['MO-C']); }); + /** + * 2026-10-27 裁决(接入编码设计 §5.1):合并键加上**主系统分公司**。 + * 为什么必须加:一个接入编码可被主系统 A/B/C 三行授权绑定 ⇒ 同一家我方分公司同一天会收到 + * 多个主系统分公司的货,而它们的**送达地址(各自分公司仓库)不同** ⇒ 并成一张单就会出现 + * "一张单两个送达地址",派车/送达/免入库取货全错。 + */ + it('同一天但**主系统分公司不同** ⇒ 拆成两个桶(不得并单)', () => { + const buckets = bucketGroupsByDeliveryDate([ + group('MO-A1', '2026-10-09', ['土豆'], 'BR002'), + group('MO-B1', '2026-10-09', ['白菜'], 'BR003'), + ]); + expect(buckets).toHaveLength(2); + expect(buckets.map((b) => `${b.mainBranchCode}@${b.deliveryDate}`)).toEqual([ + 'BR002@2026-10-09', + 'BR003@2026-10-09', + ]); + expect(buckets[0].groups.map((g) => g.orderCode)).toEqual(['MO-A1']); + expect(buckets[1].groups.map((g) => g.orderCode)).toEqual(['MO-B1']); + }); + + it('同一天 + 同一主系统分公司 ⇒ 仍并成一张单(原口径不回退)', () => { + const buckets = bucketGroupsByDeliveryDate([ + group('MO-A1', '2026-10-09', ['土豆'], 'BR002'), + group('MO-A2', '2026-10-09', ['白菜'], 'BR002'), + ]); + expect(buckets).toHaveLength(1); + expect(buckets[0].mainBranchCode).toBe('BR002'); + expect(buckets[0].groups.map((g) => g.orderCode)).toEqual(['MO-A1', 'MO-A2']); + }); + + it('行里没有主系统分公司 ⇒ 归到空键(与存量占坑行同口径)', () => { + const buckets = bucketGroupsByDeliveryDate([ + group('MO-X', '2026-10-09', ['土豆']), + group('MO-Y', '2026-10-09', ['白菜'], 'BR002'), + ]); + expect(buckets).toHaveLength(2); + expect(buckets.map((b) => b.mainBranchCode)).toEqual(['', 'BR002']); + }); + it('配送日缺失时用哨兵日兜底(不丢行)', () => { const buckets = bucketGroupsByDeliveryDate([group('MO-D', null, ['土豆'])]); expect(buckets).toHaveLength(1);