采购与备货表: 新增「规格」列(展示录单规格)
两表原「商品描述」列取的是商品库 skus.spec/product_catalog.spec,没取录单写的 order_items.spec(ff15808)⇒ 商品库无规格时该列为空。新增独立只读「规格」列(商品名后,三语),取值录单规格优先 → 商品库兜底(采购再兜底 remark 里的 规格:)。 - 三处查询带出 order_spec / order_item_spec(备货内部表、供应商看板、采购列表) - 不改「商品描述」列,也不动分组折叠/复制/导出文本与 purchase_status - 新增契约测试 purchasePrepSpecColumn.contract.test.ts 导出/打印同步(原设计 §4 ⑥)本轮不做。
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
> 2026-10-16 · 开发者需求(附两张截图:采购列表、供应商备货表):「这样我们的采购与供应商备货 就好看到具体是哪一个商品 采购的规格是多少 就不会乱采购了」「当前这两块的表单还没有规格的字段展示」。
|
||||
>
|
||||
> **状态:设计草案,待拍板 §4 后编码。** 本需求接着同日的 [`20261016-订单详情展示商品规格.md`](./20261016-订单详情展示商品规格.md)(录单规格已落 `order_items.spec`):**规格已经存了,只是这两张表没把它取出来** —— 需要先定「展示形态 / 取数来源 / 位置」三件口径。
|
||||
> **状态:已实现(v2)。** 开发者 2026-10-16 回「可以 先按照你说的做 然后 第六的先别做」⇒ 采纳 §4 的 ①–⑤、**⑥(导出/打印同步)不做**。本需求接着同日的 [`20261016-订单详情展示商品规格.md`](./20261016-订单详情展示商品规格.md)(录单规格已落 `order_items.spec`):**规格已经存了,只是这两张表没把它取出来**。
|
||||
|
||||
## 1. 需求
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
- 优点:零新增文案、零列结构调整。
|
||||
- 代价:**连带改 F8**(分组键会跟着变、复制/导出文本会变),且「商品描述」语义漂移(原本只指商品库档案)。⇒ 不推荐。
|
||||
|
||||
## 4. 待你拍板(附我的默认)
|
||||
## 4. 口径(开发者 2026-10-16 采纳 ①–⑤,⑥ 不做)
|
||||
|
||||
| # | 问题 | 我的默认 |
|
||||
| --- | --- | --- |
|
||||
@@ -60,25 +60,28 @@
|
||||
| 平台(新业务表) | 否 | **不加表**(只加展示字段) |
|
||||
| AI | 否 | 无 AI 调用 |
|
||||
|
||||
## 6. 验收标准(确认后细化)
|
||||
## 6. 验收标准(已按此实现)
|
||||
|
||||
1. 客户录单写了规格 ⇒ 采购行/备货行的「规格」列**显示该规格**;录单没写但商品库有 ⇒ 显示商品库规格;都没有 ⇒ 留空。
|
||||
2. 采购行的手工填规格(F7)在录单规格/商品库都空时能兜底显示。
|
||||
3. 回归:不改「商品描述」列、不改分组折叠、不改复制/导出文本、不改任何 `purchase_status` / 备货状态流转;两表列数/对齐不受影响。
|
||||
|
||||
## 7. 落点(确认后细化)
|
||||
## 7. 落点(v2 实现)
|
||||
|
||||
| 文件 | 拟改动 |
|
||||
| 文件 | 改动 |
|
||||
| --- | --- |
|
||||
| `server/src/services/preparationListQueryService.ts` | LATERAL 增 `oi0.spec`、SELECT 增 `oi.spec AS order_spec` |
|
||||
| `server/src/services/purchaseOrderQueryService.ts` | `order_items` SELECT 增 `spec`;`preEnriched` 增 `order_item_spec` |
|
||||
| `src/pages/purchase/supplierPreparation/supplierPreparationHelpers.ts` | 列定义增 `spec`(`col.spec`);行类型增 `order_spec` |
|
||||
| `src/pages/purchase/supplierPreparation/SupplierPreparationPage.tsx` | 行映射增 `order_spec`;渲染 `spec` 列 |
|
||||
| `src/pages/purchase/PurchaseManagement.tsx` | 列定义增 `spec`;`PurchaseOrder` 增 `order_item_spec`;渲染 `spec` 列 |
|
||||
| `src/i18n/locales/{zh-CN,en,id}/{purchase,preparations}.ts` | 新增 `col.spec` 三语 |
|
||||
| `server/src/services/preparationListQueryService.ts` | `fromSql` LATERAL 与 `selectSql`/`sendableSql` 均带出 `oi.spec AS order_spec` |
|
||||
| `server/src/services/supplierPrepBoardService.ts` | 供应商看板同口径(LATERAL + SELECT + 行映射 `order_spec`) |
|
||||
| `server/src/services/purchaseOrderQueryService.ts` | `order_items` 查询增 `spec`;行上 `order_item_spec`(自采行 `null`) |
|
||||
| `src/pages/purchase/supplierPreparation/supplierPreparationHelpers.ts` | 行类型增 `order_spec`;`formatPrepSpec`;列定义增 `spec`(商品名后) |
|
||||
| `src/pages/purchase/supplierPreparation/SupplierPreparationPage.tsx` | 两处行映射 + 两处渲染增 `spec` 列 |
|
||||
| `src/pages/purchase/PurchaseManagement.tsx` | `formatPurchaseSpec`;列定义增 `spec`(商品名后);分组行 + 明细行渲染 |
|
||||
| `src/i18n/locales/{zh-CN,en,id}/{purchase,preparations}.ts` | 新增 `col.spec` 三语(规格 / Spec / Spesifikasi) |
|
||||
| `src/pages/purchase/purchasePrepSpecColumn.contract.test.ts` | 新增契约测试(后端带出 / 前端取值与位置 / 三语) |
|
||||
|
||||
## 8. 修订记录
|
||||
|
||||
| 版本 | 日期 | 变更 |
|
||||
| --- | --- | --- |
|
||||
| v1 | 2026-10-16 | 首版设计(含 §4 六项待拍板) |
|
||||
| v2 | 2026-10-16 | 开发者采纳 ①–⑤、⑥不做 ⇒ 实现:三处查询带出录单规格(`order_spec`/`order_item_spec`)+ 两表新增只读「规格」列(商品名后,三语)+ 契约测试;不改「商品描述」列与分组/复制/导出 |
|
||||
|
||||
@@ -59,7 +59,7 @@ AI 提示词清理已停用条目(7 条归档不删、清单过滤 archived、
|
||||
订单入库点「**退回**」**先弹二次确认**(开发者:「点击后需要触发一个弹窗二次确认才行」)—— 退回不可逆(按不合格退回、不入库),现改为确定才置不合格并退供、取消则原地不动(4 行改动,退回语义一字未动;Web 验收页同位置未在本次范围),见 [20261016-订单入库退回二次确认.md](./20261016-订单入库退回二次确认.md)。
|
||||
订单入库**补齐字段:规格 / 生产日期 / 保质期 / 生产产地**(设计草案,待拍板 §4 后编码):对齐「库存入库」字段集,落点同口径——规格→`product_catalog.spec`(触发器同步 `skus.spec`)、产地→`skus.origin`(复用 `applyArchiveWriteback`,只回写人工改过的字段)、生产日期→`inventory.production_date`、保质期→`inventory.shelf_life` 并由生产日期+保质期推算 `expiry_date`(复用 `deriveExpiryDate`);⚠️ 验收链路现状**既不写 shelf_life/expiry 也不做档案回写**,本需求会新增这两类写入,见 [20261016-订单入库补规格生产日期保质期产地.md](./20261016-订单入库补规格生产日期保质期产地.md)。
|
||||
订单详情**展示「商品规格」**(**已实现**,2026-10-16):录单已能填规格(`acb652d`)**但原先没落库**(`order_items` 无 spec 列、建单 INSERT 未包含)⇒ 加列 `order_items.spec VARCHAR(60)`(迁移 `20261050`)+ 建单写入,再在详情表(`OrderDetailDeliveryNotePanel.tsx`,**列对齐靠手写 colSpan**)商品名后加只读「规格」列(三语文案 `orders.detail.colSpec`);不动抵扣/成本/状态链,不新增表,见 [20261016-订单详情展示商品规格.md](./20261016-订单详情展示商品规格.md)。
|
||||
采购页 / 供应商备货表**展示「商品规格」**(设计草案,待拍板 §4 后编码):两表**已有「商品描述」列**(= 规格 + 品牌)但取的是**商品库** `skus.spec`/`product_catalog.spec`、**没取录单写的 `order_items.spec`**(上一提交 `ff15808`)⇒ 商品库没维护规格时该列为空(截图显示 `-`);拟**新增独立只读「规格」列**(商品名后),取「录单规格优先 → 商品库兜底」(采购再兜底手工 `规格:`);不改现「商品描述」(它还喂分组键/复制/导出),不动 `purchase_status` 与备货流转,见 [20261016-采购与备货表展示商品规格.md](./20261016-采购与备货表展示商品规格.md)。
|
||||
采购页 / 供应商备货表**展示「商品规格」**(**已实现**,2026-10-16):两表**已有「商品描述」列**(= 规格 + 品牌)但取的是**商品库** `skus.spec`/`product_catalog.spec`、**没取录单写的 `order_items.spec`**(上一提交 `ff15808`)⇒ 商品库没维护规格时该列为空(截图显示 `-`);已**新增独立只读「规格」列**(商品名后,三语),取「录单规格优先 → 商品库兜底」(采购再兜底手工 `规格:`,三处查询带出 `order_spec`/`order_item_spec`);不改现「商品描述」(它还喂分组键/复制/导出),不动 `purchase_status` 与备货流转;导出/打印同步本轮不做,见 [20261016-采购与备货表展示商品规格.md](./20261016-采购与备货表展示商品规格.md)。
|
||||
批次报告**推送到主系统**(第九批「批次报告同步」我方推送侧:按备货行逐条登记到主系统既有「供应商上传报告」通道、台账按 `(prep_id, report_type)` 去重、**未绑定/非主系统下发的行一律不推**、默认关)见 [20261011-批次报告推送主系统.md](./20261011-批次报告推送主系统.md)。
|
||||
库存**全额抵扣即视为已履约**(修「抵扣完了订单还停在待备货」:履约判据接受『链接的自采单已取消』+ 对账记录未推进原因)见 [20261012-库存全额抵扣即视为已履约(修订单卡在待备货).md](./20261012-库存全额抵扣即视为已履约(修订单卡在待备货).md)。
|
||||
订单详情**「报告」列并显示批次报告**(此前只显示质检报告 ⇒ 抄手皮那几批明明绑了报告、订单行却空白;批次判据与推送侧同口径、只显示已人工确认、失败降级不卡详情)见 [20261012-订单详情显示批次报告.md](./20261012-订单详情显示批次报告.md)。
|
||||
|
||||
@@ -361,7 +361,7 @@ export async function listPreparationsForWebPage(
|
||||
const fromSql = `FROM supplier_preparations sp
|
||||
LEFT JOIN skus s ON s.sku_code = sp.sku_code
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT oi0.item_name, oi0.unit, oi0.ordered_unit, oi0.processing_method, oi0.processing_owner, oi0.remark
|
||||
SELECT oi0.item_name, oi0.unit, oi0.ordered_unit, oi0.processing_method, oi0.processing_owner, oi0.remark, oi0.spec
|
||||
FROM order_items oi0
|
||||
WHERE oi0.order_code = sp.order_code
|
||||
AND oi0.sku_code IS NOT DISTINCT FROM sp.sku_code
|
||||
@@ -391,6 +391,7 @@ export async function listPreparationsForWebPage(
|
||||
COALESCE(NULLIF(TRIM(s.sku_name), ''), sp.item_name, oi.item_name, sp.sku_code) AS item_name,
|
||||
s.sku_name,
|
||||
s.spec AS specification,
|
||||
oi.spec AS order_spec,
|
||||
s.brand AS product_brand,
|
||||
s.category_code AS sku_category_code,
|
||||
cat.category_name,
|
||||
@@ -468,6 +469,7 @@ export async function listPreparationsForWebPage(
|
||||
COALESCE(NULLIF(TRIM(s.sku_name), ''), sp.item_name, oi.item_name, sp.sku_code) AS item_name,
|
||||
s.sku_name,
|
||||
s.spec AS specification,
|
||||
oi.spec AS order_spec,
|
||||
s.brand AS product_brand,
|
||||
s.category_code AS sku_category_code,
|
||||
cat.category_name,
|
||||
|
||||
@@ -989,7 +989,7 @@ export async function listPurchaseOrdersForManagement(
|
||||
orderCodes.length
|
||||
? pool.query(
|
||||
`SELECT id, order_code, sku_code, supplier_code, item_name, quantity, unit,
|
||||
category_code, processing_method, price, locked_price, unit_cost, remark
|
||||
category_code, processing_method, price, locked_price, unit_cost, remark, spec
|
||||
FROM order_items WHERE order_code = ANY($1::text[])`,
|
||||
[orderCodes]
|
||||
)
|
||||
@@ -1077,6 +1077,8 @@ export async function listPurchaseOrdersForManagement(
|
||||
processing_method: displayOrderItem?.processing_method || item.processing_method || '',
|
||||
product_spec: String(sku?.spec || catalog?.spec || '').trim() || null,
|
||||
product_brand: String(sku?.brand || catalog?.brand || '').trim() || null,
|
||||
// 录单写的规格(order_items.spec):优先展示,商品库规格作兜底
|
||||
order_item_spec: String(displayOrderItem?.spec || '').trim() || null,
|
||||
specification: String(sku?.spec || catalog?.spec || '').trim() || '',
|
||||
direct_delivery:
|
||||
sku?.direct_delivery === true &&
|
||||
@@ -1343,6 +1345,7 @@ export async function listPurchaseOrdersForManagement(
|
||||
order_item_remark: null,
|
||||
product_spec: String(sku?.spec || catalog?.spec || '').trim() || null,
|
||||
product_brand: String(sku?.brand || catalog?.brand || '').trim() || null,
|
||||
order_item_spec: null,
|
||||
purchase_status: spi.inventory_id ? 30 : 10,
|
||||
inbound_pending: !spi.inventory_id,
|
||||
inspection_id: spi.inspection_id || null,
|
||||
|
||||
@@ -24,6 +24,8 @@ export type SupplierPrepBoardRow = {
|
||||
transferred_to_purchase: boolean;
|
||||
purchase_code?: string | null;
|
||||
specification?: string | null;
|
||||
/** 录单写的规格 order_items.spec(优先展示) */
|
||||
order_spec?: string | null;
|
||||
product_brand?: string | null;
|
||||
unit?: string | null;
|
||||
delivery_date?: string | null;
|
||||
@@ -84,6 +86,7 @@ export async function listSupplierPrepBoard(input: {
|
||||
COALESCE(NULLIF(TRIM(s.sku_name), ''), sp.item_name, oi.item_name, sp.sku_code) AS item_name,
|
||||
s.sku_name,
|
||||
s.spec AS specification,
|
||||
oi.spec AS order_spec,
|
||||
s.brand AS product_brand,
|
||||
s.category_code AS sku_category_code,
|
||||
cat.category_name,
|
||||
@@ -107,7 +110,7 @@ export async function listSupplierPrepBoard(input: {
|
||||
LEFT JOIN skus s ON s.sku_code = sp.sku_code
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT oi0.item_name, oi0.unit, oi0.ordered_unit, oi0.processing_method, oi0.processing_owner,
|
||||
NULLIF(TRIM(oi0.remark), '') AS remark
|
||||
NULLIF(TRIM(oi0.remark), '') AS remark, oi0.spec
|
||||
FROM order_items oi0
|
||||
WHERE oi0.order_code = sp.order_code
|
||||
AND oi0.sku_code IS NOT DISTINCT FROM sp.sku_code
|
||||
@@ -165,6 +168,7 @@ export async function listSupplierPrepBoard(input: {
|
||||
transferred_to_purchase: Boolean(row.transferred_to_purchase),
|
||||
purchase_code: row.purchase_code != null ? String(row.purchase_code) : null,
|
||||
specification: row.specification != null ? String(row.specification) : null,
|
||||
order_spec: row.order_spec != null ? String(row.order_spec).trim() || null : null,
|
||||
product_brand: row.product_brand != null ? String(row.product_brand) : null,
|
||||
unit: row.unit != null ? String(row.unit) : null,
|
||||
delivery_date: row.delivery_date != null ? String(row.delivery_date) : null,
|
||||
|
||||
@@ -86,6 +86,7 @@ export const preparations: MessageDict = {
|
||||
'col.seq': 'No.',
|
||||
'col.delivery_date': 'Delivery date',
|
||||
'col.product': 'Product',
|
||||
'col.spec': 'Spec',
|
||||
'col.product_desc': 'Description',
|
||||
'col.qty': 'Qty',
|
||||
'col.unit': 'Unit',
|
||||
|
||||
@@ -4,6 +4,7 @@ export const purchase: MessageDict = {
|
||||
'col.seq': 'No.',
|
||||
'col.created_day': 'Delivery',
|
||||
'col.product_name': 'Product',
|
||||
'col.spec': 'Spec',
|
||||
'col.product_desc': 'Description',
|
||||
'col.plan_qty': 'Planned qty',
|
||||
'col.unit': 'Unit',
|
||||
|
||||
@@ -86,6 +86,7 @@ export const preparations: MessageDict = {
|
||||
'col.seq': 'No.',
|
||||
'col.delivery_date': 'Tgl kirim',
|
||||
'col.product': 'Nama produk',
|
||||
'col.spec': 'Spesifikasi',
|
||||
'col.product_desc': 'Deskripsi',
|
||||
'col.qty': 'Jml',
|
||||
'col.unit': 'Satuan',
|
||||
|
||||
@@ -4,6 +4,7 @@ export const purchase: MessageDict = {
|
||||
'col.seq': 'No.',
|
||||
'col.created_day': 'Tgl kirim',
|
||||
'col.product_name': 'Produk',
|
||||
'col.spec': 'Spesifikasi',
|
||||
'col.product_desc': 'Deskripsi',
|
||||
'col.plan_qty': 'Jml rencana',
|
||||
'col.unit': 'Satuan',
|
||||
|
||||
@@ -85,6 +85,7 @@ export const preparations: MessageDict = {
|
||||
'col.seq': '序号',
|
||||
'col.delivery_date': '配送日',
|
||||
'col.product': '商品名称',
|
||||
'col.spec': '规格',
|
||||
'col.product_desc': '商品描述',
|
||||
'col.qty': '数量',
|
||||
'col.unit': '单位',
|
||||
|
||||
@@ -4,6 +4,7 @@ export const purchase: MessageDict = {
|
||||
'col.seq': '序号',
|
||||
'col.created_day': '配送日',
|
||||
'col.product_name': '商品名称',
|
||||
'col.spec': '规格',
|
||||
'col.product_desc': '商品描述',
|
||||
'col.plan_qty': '计划数量',
|
||||
'col.unit': '单位',
|
||||
|
||||
@@ -115,6 +115,7 @@ type PurchaseColumnId =
|
||||
| 'seq'
|
||||
| 'created_day'
|
||||
| 'product_name'
|
||||
| 'spec'
|
||||
| 'product_desc'
|
||||
| 'plan_qty'
|
||||
| 'unit'
|
||||
@@ -133,6 +134,7 @@ const PURCHASE_COLUMNS_ALL: Array<TableColumnDef<PurchaseColumnId>> = [
|
||||
{ id: 'seq', label: 'col.seq' },
|
||||
{ id: 'created_day', label: 'col.created_day' },
|
||||
{ id: 'product_name', label: 'col.product_name' },
|
||||
{ id: 'spec', label: 'col.spec' },
|
||||
{ id: 'product_desc', label: 'col.product_desc' },
|
||||
{ id: 'plan_qty', label: 'col.plan_qty' },
|
||||
{ id: 'unit', label: 'col.unit' },
|
||||
@@ -199,6 +201,8 @@ interface PurchaseOrder {
|
||||
product_spec?: string | null;
|
||||
/** 商品品牌:客户订单对应 SKU 的 skus.brand */
|
||||
product_brand?: string | null;
|
||||
/** 录单写的规格:order_items.spec(优先展示) */
|
||||
order_item_spec?: string | null;
|
||||
purchase_status: number;
|
||||
direct_delivery?: boolean;
|
||||
requires_photo_inspection?: boolean;
|
||||
@@ -369,6 +373,17 @@ function formatProductDesc(
|
||||
return [spec, brand].filter(Boolean).join(';');
|
||||
}
|
||||
|
||||
/** 规格列取值:录单写的规格优先 → 商品库规格 → 采购手工填的规格(存 remark) */
|
||||
function formatPurchaseSpec(
|
||||
p: Pick<PurchaseOrder, 'order_item_spec' | 'product_spec' | 'specification' | 'remark'>
|
||||
): string {
|
||||
return (
|
||||
String(p.order_item_spec || '').trim() ||
|
||||
String(p.product_spec || p.specification || '').trim() ||
|
||||
parseSpecFromRemark(p.remark)
|
||||
);
|
||||
}
|
||||
|
||||
const SYSTEM_PURCHASE_REMARK_SEGMENT =
|
||||
/^(?:\[[^\]]+\]\s*)?(?:(?:一级分类|二级分类|分类)「[^」]*」无绑定供应商[,,]\s*流转至自有采购员|未匹配商品「[^」]*」[,,]\s*流转至自有采购员自采|未匹配商品:\s*.+|无商品分类,按规则流转至自有采购员|订单保存:(?:分类无供应商|无分类商品)|强制覆盖:订单明细必须进自采或备货,禁止遗漏|可修改时限内新增商品自动分配:未匹配供应商,转自采|手动分配:未指定供应商,转自采|分配兜底:未匹配供应商,转自采|采购员加单:自采|改派供应商,取消原无货流转自采|分配重新匹配供应商,取消原无货流转自采|改回自采,恢复待采|库存抵扣\s+[0-9.eE+-]+\s*[,,]?\s*本单采购\s+[0-9.eE+-]+)$/;
|
||||
|
||||
@@ -3132,6 +3147,9 @@ export const PurchaseManagement: React.FC<PurchaseManagementProps> = ({
|
||||
[
|
||||
...new Set(group.purchases.map((p) => formatProductDesc(p)).filter(Boolean)),
|
||||
].join(';');
|
||||
const specText = [
|
||||
...new Set(group.purchases.map((p) => formatPurchaseSpec(p)).filter(Boolean)),
|
||||
].join(';');
|
||||
const singleEditable = singlePo ? canEditPurchaseFields(singlePo) : false;
|
||||
const singleQtyUnitEditable = singlePo ? canEditPurchaseQtyUnit(singlePo) : false;
|
||||
const singleSaleEditable = singlePo ? canEditSalePrice(singlePo) : false;
|
||||
@@ -3207,6 +3225,8 @@ export const PurchaseManagement: React.FC<PurchaseManagementProps> = ({
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
case 'spec':
|
||||
return td(specText || '-');
|
||||
case 'product_desc':
|
||||
return td(desc || '-');
|
||||
case 'plan_qty':
|
||||
@@ -3437,6 +3457,7 @@ export const PurchaseManagement: React.FC<PurchaseManagementProps> = ({
|
||||
expanded && group.purchases.length > 1
|
||||
? group.purchases.map((p, itemIndex) => {
|
||||
const pDesc = formatProductDesc(p);
|
||||
const pSpec = formatPurchaseSpec(p);
|
||||
const nestedEditable = canEditPurchaseFields(p);
|
||||
const nestedQtyUnitEditable = canEditPurchaseQtyUnit(p);
|
||||
const nestedSaleEditable = canEditSalePrice(p);
|
||||
@@ -3478,6 +3499,8 @@ export const PurchaseManagement: React.FC<PurchaseManagementProps> = ({
|
||||
<div className="app-foreground-muted">{p.purchase_code}</div>
|
||||
</div>
|
||||
);
|
||||
case 'spec':
|
||||
return td(pSpec || '-');
|
||||
case 'product_desc':
|
||||
return td(pDesc || '-');
|
||||
case 'plan_qty':
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
/**
|
||||
* 采购页 / 供应商备货表 展示「商品规格」(2026-10-16 开发者需求)。
|
||||
* 设计 docs/design/20261016-采购与备货表展示商品规格.md。
|
||||
*
|
||||
* 关键:两表原本的「商品描述」列取的是**商品库**档案规格(`skus.spec` / `product_catalog.spec`),
|
||||
* 没取录单写的 `order_items.spec` ⇒ 商品库无规格时该列为空。本改动新增独立「规格」列,
|
||||
* 取值「录单规格优先 → 商品库兜底」(采购再兜底手工 `规格:`),且**不动**「商品描述」列。
|
||||
*/
|
||||
const read = (rel: string) => readFileSync(new URL(rel, import.meta.url), 'utf8');
|
||||
|
||||
const prepService = read('../../../server/src/services/preparationListQueryService.ts');
|
||||
const boardService = read('../../../server/src/services/supplierPrepBoardService.ts');
|
||||
const purchaseService = read('../../../server/src/services/purchaseOrderQueryService.ts');
|
||||
const prepHelpers = read('./supplierPreparation/supplierPreparationHelpers.ts');
|
||||
const prepPage = read('./supplierPreparation/SupplierPreparationPage.tsx');
|
||||
const purchasePage = read('./PurchaseManagement.tsx');
|
||||
const locale = (l: string, ns: string) => read(`../../i18n/locales/${l}/${ns}.ts`);
|
||||
|
||||
describe('后端:带出录单规格 order_spec / order_item_spec', () => {
|
||||
it('备货表(内部)两条 SELECT + LATERAL 都带 oi.spec', () => {
|
||||
expect(prepService).toContain('oi0.processing_owner, oi0.remark, oi0.spec');
|
||||
// selectSql 与 sendableSql 各一处
|
||||
expect((prepService.match(/oi\.spec AS order_spec,/g) || []).length).toBe(2);
|
||||
});
|
||||
|
||||
it('备货看板(供应商账号)同口径', () => {
|
||||
expect(boardService).toContain('oi.spec AS order_spec,');
|
||||
expect(boardService).toContain('AS remark, oi0.spec');
|
||||
expect(boardService).toContain(
|
||||
'order_spec: row.order_spec != null ? String(row.order_spec).trim() || null : null,'
|
||||
);
|
||||
});
|
||||
|
||||
it('采购列表:order_items 查询带 spec,行上给出 order_item_spec(自采行 null)', () => {
|
||||
expect(purchaseService).toContain('unit_cost, remark, spec');
|
||||
expect(purchaseService).toContain(
|
||||
"order_item_spec: String(displayOrderItem?.spec || '').trim() || null,"
|
||||
);
|
||||
expect(purchaseService).toContain('order_item_spec: null,');
|
||||
});
|
||||
});
|
||||
|
||||
describe('前端:规格列取值与位置', () => {
|
||||
it('备货表:formatPrepSpec = 录单规格优先,商品库兜底', () => {
|
||||
expect(prepHelpers).toContain("return String(p.order_spec || p.specification || '').trim();");
|
||||
const iProduct = prepHelpers.indexOf("{ id: 'product', label: 'col.product' }");
|
||||
const iSpec = prepHelpers.indexOf("{ id: 'spec', label: 'col.spec' }");
|
||||
const iDesc = prepHelpers.indexOf("{ id: 'product_desc', label: 'col.product_desc' }");
|
||||
expect(iProduct).toBeGreaterThanOrEqual(0);
|
||||
expect(iSpec).toBeGreaterThan(iProduct);
|
||||
expect(iDesc).toBeGreaterThan(iSpec);
|
||||
});
|
||||
|
||||
it('备货表:行映射带 order_spec,两处渲染都出 spec 单元格', () => {
|
||||
expect(
|
||||
(prepPage.match(
|
||||
/order_spec: row\.order_spec != null \? String\(row\.order_spec\)\.trim\(\) \|\| null : null,/g
|
||||
) || []).length
|
||||
).toBe(2);
|
||||
expect(prepPage).toContain("const specText = formatPrepSpec(prep) || '-';");
|
||||
expect(prepPage).toContain("const nestSpec = formatPrepSpec(source) || '-';");
|
||||
expect((prepPage.match(/case 'spec':/g) || []).length).toBe(2);
|
||||
});
|
||||
|
||||
it('采购页:formatPurchaseSpec = 录单 → 商品库 → 手工规格(remark)', () => {
|
||||
expect(purchasePage).toContain("String(p.order_item_spec || '').trim() ||");
|
||||
expect(/(order_item_spec[\s\S]{0,400}parseSpecFromRemark\(p\.remark\))/.test(purchasePage)).toBe(
|
||||
true
|
||||
);
|
||||
const iName = purchasePage.indexOf("{ id: 'product_name', label: 'col.product_name' }");
|
||||
const iSpec = purchasePage.indexOf("{ id: 'spec', label: 'col.spec' }");
|
||||
const iDesc = purchasePage.indexOf("{ id: 'product_desc', label: 'col.product_desc' }");
|
||||
expect(iName).toBeGreaterThanOrEqual(0);
|
||||
expect(iSpec).toBeGreaterThan(iName);
|
||||
expect(iDesc).toBeGreaterThan(iSpec);
|
||||
});
|
||||
|
||||
it('采购页:分组行与明细行都出 spec 单元格', () => {
|
||||
expect((purchasePage.match(/case 'spec':/g) || []).length).toBe(2);
|
||||
expect(purchasePage).toContain("return td(specText || '-');");
|
||||
expect(purchasePage).toContain("return td(pSpec || '-');");
|
||||
});
|
||||
|
||||
it('不改「商品描述」列(仍走 formatProductDesc/formatPrepProductDesc)', () => {
|
||||
expect(/case 'product_desc':\s+return td\(desc \|\| '-'\);/.test(purchasePage)).toBe(true);
|
||||
expect(prepPage).toContain("const productDesc = formatPrepProductDesc(prep) || '-';");
|
||||
});
|
||||
});
|
||||
|
||||
describe('三语文案 purchase.col.spec / preparations.col.spec', () => {
|
||||
it('采购页三语', () => {
|
||||
expect(locale('zh-CN', 'purchase')).toContain("'col.spec': '规格'");
|
||||
expect(locale('en', 'purchase')).toContain("'col.spec': 'Spec'");
|
||||
expect(locale('id', 'purchase')).toContain("'col.spec': 'Spesifikasi'");
|
||||
});
|
||||
|
||||
it('备货表三语', () => {
|
||||
expect(locale('zh-CN', 'preparations')).toContain("'col.spec': '规格'");
|
||||
expect(locale('en', 'preparations')).toContain("'col.spec': 'Spec'");
|
||||
expect(locale('id', 'preparations')).toContain("'col.spec': 'Spesifikasi'");
|
||||
});
|
||||
});
|
||||
@@ -90,6 +90,7 @@ import {
|
||||
formatPrepDeliveryDates,
|
||||
formatPrepOrderItemRemarks,
|
||||
formatPrepProductDesc,
|
||||
formatPrepSpec,
|
||||
formatPrepQty,
|
||||
matchesPrepStatusAndStockoutFilters,
|
||||
describePrepAiAlertMessage,
|
||||
@@ -131,6 +132,7 @@ function mapWebPrepListRow(row: Record<string, unknown>): SupplierPreparation {
|
||||
transferred_to_purchase: Boolean(row.transferred_to_purchase),
|
||||
purchase_code: row.purchase_code != null ? String(row.purchase_code) : undefined,
|
||||
specification: row.specification != null ? String(row.specification) : undefined,
|
||||
order_spec: row.order_spec != null ? String(row.order_spec).trim() || null : null,
|
||||
product_brand: row.product_brand != null ? String(row.product_brand) : null,
|
||||
unit: row.unit != null ? String(row.unit) : undefined,
|
||||
delivery_date: row.delivery_date ? normalizeDateInput(String(row.delivery_date)) : undefined,
|
||||
@@ -853,6 +855,7 @@ export const SupplierPreparationManagement: React.FC = () => {
|
||||
transferred_to_purchase: Boolean(row.transferred_to_purchase),
|
||||
purchase_code: row.purchase_code != null ? String(row.purchase_code) : undefined,
|
||||
specification: row.specification != null ? String(row.specification) : undefined,
|
||||
order_spec: row.order_spec != null ? String(row.order_spec).trim() || null : null,
|
||||
product_brand: row.product_brand != null ? String(row.product_brand) : null,
|
||||
unit: row.unit != null ? String(row.unit) : undefined,
|
||||
delivery_date: row.delivery_date
|
||||
@@ -1530,6 +1533,7 @@ export const SupplierPreparationManagement: React.FC = () => {
|
||||
prepare_status: Number(row.prepare_status) || 0,
|
||||
unit: row.unit,
|
||||
specification: row.specification,
|
||||
order_spec: row.order_spec,
|
||||
processing_method: row.processing_method,
|
||||
category_name: row.category_name,
|
||||
delivery_date: row.delivery_date,
|
||||
@@ -2282,6 +2286,7 @@ export const SupplierPreparationManagement: React.FC = () => {
|
||||
'border border-slate-700 dark:border-slate-500 px-2 py-1.5 app-foreground overflow-hidden align-middle text-center';
|
||||
const productName = getPreparationDisplayName(prep);
|
||||
const productDesc = formatPrepProductDesc(prep) || '-';
|
||||
const specText = formatPrepSpec(prep) || '-';
|
||||
const actionIds =
|
||||
prep.mergedSources
|
||||
?.filter(
|
||||
@@ -2428,6 +2433,12 @@ export const SupplierPreparationManagement: React.FC = () => {
|
||||
)}
|
||||
</td>
|
||||
);
|
||||
case 'spec':
|
||||
return (
|
||||
<td key={col.id} className={tdClass} title={specText}>
|
||||
<div className="truncate">{specText}</div>
|
||||
</td>
|
||||
);
|
||||
case 'product_desc':
|
||||
return (
|
||||
<td key={col.id} className={tdClass} title={productDesc}>
|
||||
@@ -2585,6 +2596,7 @@ export const SupplierPreparationManagement: React.FC = () => {
|
||||
const nestTd =
|
||||
'border border-slate-700 dark:border-slate-500 px-2 py-1.5 text-xs app-foreground overflow-hidden align-middle text-center';
|
||||
const nestDesc = formatPrepProductDesc(source) || '-';
|
||||
const nestSpec = formatPrepSpec(source) || '-';
|
||||
switch (col.id) {
|
||||
case 'seq':
|
||||
return (
|
||||
@@ -2616,6 +2628,12 @@ export const SupplierPreparationManagement: React.FC = () => {
|
||||
{source.delivery_date || '—'}
|
||||
</td>
|
||||
);
|
||||
case 'spec':
|
||||
return (
|
||||
<td key={col.id} className={nestTd} title={nestSpec}>
|
||||
<div className="truncate">{nestSpec}</div>
|
||||
</td>
|
||||
);
|
||||
case 'product_desc':
|
||||
return (
|
||||
<td key={col.id} className={nestTd} title={nestDesc}>
|
||||
|
||||
@@ -23,7 +23,10 @@ export interface SupplierPreparation {
|
||||
stockout_reason?: string;
|
||||
transferred_to_purchase: boolean;
|
||||
purchase_code?: string;
|
||||
/** 商品库规格 skus.spec(兜底) */
|
||||
specification?: string;
|
||||
/** 录单写的规格 order_items.spec(优先展示) */
|
||||
order_spec?: string | null;
|
||||
/** 商品库品牌 skus.brand */
|
||||
product_brand?: string | null;
|
||||
unit?: string;
|
||||
@@ -52,6 +55,14 @@ export function formatPrepProductDesc(p: {
|
||||
return [spec, brand].filter(Boolean).join(';');
|
||||
}
|
||||
|
||||
/** 规格列取值:录单写的规格优先,商品库规格兜底 */
|
||||
export function formatPrepSpec(p: {
|
||||
order_spec?: string | null;
|
||||
specification?: string | null;
|
||||
}): string {
|
||||
return String(p.order_spec || p.specification || '').trim();
|
||||
}
|
||||
|
||||
export function formatPrepQty(value: unknown) {
|
||||
const n = Number(value);
|
||||
if (!Number.isFinite(n)) return '0';
|
||||
@@ -83,6 +94,7 @@ export type SupplierPrepColumnId =
|
||||
| 'seq'
|
||||
| 'delivery_date'
|
||||
| 'product'
|
||||
| 'spec'
|
||||
| 'product_desc'
|
||||
| 'qty'
|
||||
| 'unit'
|
||||
@@ -97,6 +109,7 @@ export const SUPPLIER_PREP_COLUMNS: Array<TableColumnDef<SupplierPrepColumnId>>
|
||||
{ id: 'seq', label: 'col.seq' },
|
||||
{ id: 'delivery_date', label: 'col.delivery_date' },
|
||||
{ id: 'product', label: 'col.product' },
|
||||
{ id: 'spec', label: 'col.spec' },
|
||||
{ id: 'product_desc', label: 'col.product_desc' },
|
||||
{ id: 'qty', label: 'col.qty' },
|
||||
{ id: 'unit', label: 'col.unit' },
|
||||
|
||||
Reference in New Issue
Block a user