// @vitest-environment jsdom import { describe, expect, it } from 'vitest'; import { readFileSync } from 'node:fs'; import path from 'node:path'; import { buildDeliveryNotePrintHtml, type DeliveryNotePrintPayload, } from './deliveryNotePrint'; import { buildDeliveryHtmlTemplateDocument } from './deliveryHtmlTemplateRender'; import type { DeliveryHtmlTemplate } from './deliveryHtmlTemplates'; import type { DeliveryNotePrintGroup } from './deliveryNotePrint'; import { DELIVERY_ITEM_COLUMNS } from './exportColumnPresets'; import { DEFAULT_DELIVERY_NOTE_LAYOUT } from './printTemplates'; const FULL_CODE = 'ORD_WEB_20260923_BR002_0001'; const SHORT_CODE = '20260923_BR002_0001'; const order = { order_code: FULL_CODE, delivery_date: '2026-09-23', branch_name: '分公司', }; const group: DeliveryNotePrintGroup = { groupKey: FULL_CODE, customer_code: 'C001', customer_name: '客户甲', orders: [order], lines: [ { order_code: FULL_CODE, sku_code: 'S1', sku_name: '土豆', quantity: 1, unit: '斤', price: 12, amount: 12, }, ], }; /** * 单据上的订单号只显示短号(2026-10-06 用户要求): * `ORD_WEB_20260923_BR002_0001` → `20260923_BR002_0001`。 * 两种版式(旧版明细表 / AI HTML 模板)都要一致;分组键仍用完整单号。 */ describe('配送单订单号展示', () => { it('旧版打印文档:单据编号与抬头订单号都是短号', () => { const payload: DeliveryNotePrintPayload = { title: '配送单', groups: [group], columns: DELIVERY_ITEM_COLUMNS as DeliveryNotePrintPayload['columns'], selectedColumnIds: DELIVERY_ITEM_COLUMNS.map((col) => col.id), metaFields: ['order_code'], layout: DEFAULT_DELIVERY_NOTE_LAYOUT, }; const { html } = buildDeliveryNotePrintHtml(payload); expect(html).toContain(SHORT_CODE); expect(html).not.toContain(FULL_CODE); }); it('AI HTML 模板:{{order.order_code}} 渲染成短号', () => { const template: DeliveryHtmlTemplate = { id: 'oc', name: 'oc', html: '
| {{item.sku_name}} |