Web验收: 补规格/生产日期/保质期/产地 + 修区域候选不刷新
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

① Web「确认入库」弹窗补 4 字段(规格预填 skus.spec、生产日期 date、保质期数值+年/月/日、产地);提交带 production_date/shelf_life/archive,workflow 路由与列表同口径。
② 修 bug:存放区域候选原只在挂载时拉一次 ⇒ 新建区域后下一个商品的弹窗看不到、要刷新页面。改为 loadZoneChoices 并在每次打开弹窗时重拉。
新增契约测试 inspectionWebInboundFields。
This commit is contained in:
雨天
2026-10-16 17:47:22 +08:00
parent 8eee937a6c
commit feac8b1bb4
10 changed files with 216 additions and 13 deletions
@@ -76,7 +76,7 @@
| ③ | 规格/产地回写档案的规则 | **只回写人工改过的字段**(沿用 `20261012`),且**只对已匹配 SKU 的行** |
| ④ | 保质期是否**同时推算效期** | **是**(`expiry_date = 生产日期 + 保质期`) |
| ⑤ | 手填/识别的生产日期 vs 报告提取 | **手填优先**(报告只预填) |
| ⑥ | 是否同时补 **Web 验收**那侧 | 本轮**只做小程序**;Web 另开 |
| ⑥ | 是否同时补 **Web 验收**那侧 | **已补**(2026-10-16,v5:同字段、同口径;含区域候选刷新 bug 修复) |
| ⑦ | 加工成品行(F8) | **不显示**这四格 |
| ⑧ | 识别用哪条 prompt | **新建专用「验收识别」prompt**(字段=品名/品牌/规格/生产日期/保质期/产地;不带库存入库那条的「多商品/单据」噪声) |
| ⑨ | 「去掉 AI 判定」的形式 | **完全不再调用**(省一次 LLM;代码/prompt 保留) |
@@ -108,3 +108,4 @@
| v2 | 2026-10-16 | 扩写:**拍照改为识别商品信息**(复用库存入库那套,保住 `prepackaged_scan` 闸门)+ **去掉 AI 质量自动判定**(代码/prompt 保留);新增 §3.5/§3.6、§4-⑧⑨⑩⑪ |
| v3 | 2026-10-16 | 实现(按 §4 默认):① 卡片新增 规格/生产日期/保质期/产地 输入(`card-r3`,选填);② 拍照改走 `recognizeStockInboundLines` 预填四字段(只补空);③ 去掉 AI 判定(`analyzeInspectionQuality` 不再接,去掉 ai-verdict 与结果 picker,移除 `!aiDone` 闸门);④ 入库写 `inventory.shelf_life`/`expiry_date`(`deriveExpiryDate`)+ 人工改过时才回写 `product_catalog.spec`/`skus.origin`(`applyArchiveWriteback`);列表带出 `skus.spec` 预填规格 |
| v4 | 2026-10-16 | 开发者:「保质期应该是一个数字输入框加一个年月日选择」⇒ 保质期改为**数值输入 + 年/月/日 单位选择**(对齐库存入库,复用 `miniprogram/utils/shelfLife.js`:`SHELF_LIFE_UNITS`/`applyShelfLifeFromAi`/`shelfLifeTextFromLine`);提交时合成原文(如「6个月」) |
| v5 | 2026-10-16 | **Web 验收弹窗(`InspectionManagement.tsx`)同步补 4 字段**(规格预填 `skus.spec`、生产日期 date、保质期数值+年/月/日、产地;提交带 `production_date`/`shelf_life`/`archive`;workflow 路由与 `inspectionQueryService` 列表同口径);并**修 bug**:区域候选改为 `loadZoneChoices` 并在每次打开弹窗时重拉(新建区域下一单立即可选,无需刷新页面) |
@@ -363,6 +363,10 @@ router.post('/inspection/submit', authMiddleware, async (req: AuthRequest, res:
inspector_id: req.userId,
processing_details: req.body?.processing_details,
storage_zone: req.body?.storage_zone,
// 生产日期 / 保质期原文 / 人工改过的档案字段(规格/产地)—— 2026-10-16 补齐
production_date: req.body?.production_date ? String(req.body.production_date) : null,
shelf_life: req.body?.shelf_life ? String(req.body.shelf_life) : null,
archive: req.body?.archive ?? null,
watermark_meta: req.body?.watermark_meta,
location: req.body?.location,
confirm_over_qty: parseConfirmOverQty(req.body),
@@ -293,6 +293,7 @@ export async function listInspectionsForManagement(
const listResult = await pool.query(
`SELECT i.*,
sk.sku_name,
sk.spec AS sku_spec,
sk.unit AS sku_unit,
sk.category_code AS sku_category_code,
cat.category_name,
@@ -319,6 +320,7 @@ export async function listInspectionsForManagement(
const rows = listResult.rows.map((row) => ({
...row,
sku_name: row.sku_name || row.order_item_name || row.sku_code,
spec: row.sku_spec || null,
unit: row.unit || row.order_item_unit || row.sku_unit || '斤',
category_code: row.sku_category_code || row.order_item_category_code || null,
category_name: row.category_name || row.order_item_category_name || null,
+5
View File
@@ -193,6 +193,11 @@ export const inspection: MessageDict = {
'qc.perUnit': 'Cost per {unit}',
'qc.unit': 'Unit',
'qc.unitPh': 'e.g. jin, piece, case',
'qc.shelfValuePh': 'Value',
'qc.shelfUnit': 'Unit',
'qc.shelfYear': 'Year',
'qc.shelfMonth': 'Month',
'qc.shelfDay': 'Day',
'qc.total': 'Inbound total ¥{amount}',
'loss.title': 'Loss note',
'loss.linked':
+5
View File
@@ -193,6 +193,11 @@ export const inspection: MessageDict = {
'qc.perUnit': 'Biaya per {unit}',
'qc.unit': 'Satuan',
'qc.unitPh': 'mis. jin, pcs, dus',
'qc.shelfValuePh': 'Nilai',
'qc.shelfUnit': 'Satuan',
'qc.shelfYear': 'Tahun',
'qc.shelfMonth': 'Bulan',
'qc.shelfDay': 'Hari',
'qc.total': 'Total masuk ¥{amount}',
'loss.title': 'Catatan susut',
'loss.linked':
+5
View File
@@ -192,6 +192,11 @@ export const inspection: MessageDict = {
'qc.perUnit': '每 {unit} 成本',
'qc.unit': '单位',
'qc.unitPh': '如:斤、件、箱',
'qc.shelfValuePh': '数值',
'qc.shelfUnit': '单位',
'qc.shelfYear': '年',
'qc.shelfMonth': '月',
'qc.shelfDay': '日',
'qc.total': '入库合计 ¥{amount}',
'loss.title': '损耗说明',
'loss.linked':
+112 -12
View File
@@ -56,6 +56,8 @@ import {
import { useFetchGeneration } from '../../hooks/useFetchGeneration';
import { submitInspectionCompliance } from '../../utils/inspectionCompliance';
import { listInspectionsManagementApi, fetchInboundLabelPrintApi, setInboundLabelPrintApi, fetchIndependentInboundFlowApi, setIndependentInboundFlowApi, amendInspectionInboundApi, listInventoryStorageZonesApi } from '../../utils/workflowApi';
import { buildBatchRowArchive } from '../../utils/inboundArchiveBatch';
import { composeShelfLifeText } from '../../utils/shelfLife';
import {
validateGeneralImageFile,
isGeneralImageFile,
@@ -291,6 +293,8 @@ interface InspectionTask {
actual_qty: number;
/** 该商品上次入库的存放区域(验收默认值,来自 inventory) */
last_storage_zone?: string | null;
/** 商品库规格(验收「规格」预填:商品有就带过去) */
spec?: string | null;
quality_rating: string;
loss_qty: number;
loss_reason: string;
@@ -633,25 +637,34 @@ export const InspectionManagement: React.FC = () => {
/** 入库后存放区域(自由文本;候选取自既有批次区域,输入新值即新增) */
const [storageZone, setStorageZone] = useState('');
const [zoneChoices, setZoneChoices] = useState<string[]>([]);
/** 规格 / 生产日期 / 保质期 / 产地(2026-10-16 补齐,选填;规格预填商品库值、只回写人工改过的) */
const [specInput, setSpecInput] = useState('');
const [specEdited, setSpecEdited] = useState(false);
const [productionDate, setProductionDate] = useState('');
const [shelfLifeValue, setShelfLifeValue] = useState('');
const [shelfLifeUnit, setShelfLifeUnit] = useState('');
const [originInput, setOriginInput] = useState('');
const [originEdited, setOriginEdited] = useState(false);
const [isAnalyzing, setIsAnalyzing] = useState(false);
const [showGradeConfirm, setShowGradeConfirm] = useState(false);
const selectedTaskPhotoRequired = selectedTask?.requires_photo_inspection !== false;
const selectedTaskNeedsProcessing = selectedTask?.needs_processing === true;
const inspectionModalReadonly = Boolean(selectedTask && isInspectionCompleted(selectedTask));
// 存放区域候选(只读、失败即空:不阻塞验收)
// 存放区域候选(只读、失败即空:不阻塞验收)。
// ⚠️ 提成函数:**每次打开入库弹窗都重拉**,否则刚新建的区域在下一单里看不到(需刷新页面)。
const loadZoneChoices = async () => {
try {
const res = await listInventoryStorageZonesApi();
setZoneChoices((res.data || []).filter(Boolean));
} catch {
setZoneChoices([]);
}
};
useEffect(() => {
let cancelled = false;
void listInventoryStorageZonesApi()
.then((res) => {
if (!cancelled) setZoneChoices((res.data || []).filter(Boolean));
})
.catch(() => {
if (!cancelled) setZoneChoices([]);
});
return () => {
cancelled = true;
};
void loadZoneChoices();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const zoneOptions = useMemo(
@@ -929,6 +942,16 @@ export const InspectionManagement: React.FC = () => {
setInboundUnit(task.unit || '斤');
// 默认值:该商品上次入库的区域(可改)
setStorageZone(String(task.last_storage_zone || '').trim());
// 规格预填商品库值(「商品有就带过去」);生产日期/保质期/产地留空
setSpecInput(String(task.spec || '').trim());
setSpecEdited(false);
setProductionDate('');
setShelfLifeValue('');
setShelfLifeUnit('');
setOriginInput('');
setOriginEdited(false);
// 每次打开都刷新区域候选:刚在上一单新建的区域,下一单应立即可选(无需刷新页面)
void loadZoneChoices();
};
useNotificationDeepLink((code, openDetail) => {
@@ -1190,6 +1213,13 @@ export const InspectionManagement: React.FC = () => {
purchase_price: purchasePrice,
unit: inboundUnit,
storage_zone: storageZone.trim() || undefined,
production_date: productionDate || undefined,
shelf_life: composeShelfLifeText(shelfLifeValue, shelfLifeUnit) || undefined,
archive:
buildBatchRowArchive(
{ spec: specInput, origin: originInput },
{ specEdited, originEdited }
) || undefined,
processing_details: processingList,
location: profile?.branch_name || undefined,
watermark_meta: {
@@ -1274,6 +1304,13 @@ export const InspectionManagement: React.FC = () => {
purchase_price: purchasePrice,
unit: inboundUnit,
storage_zone: storageZone.trim() || undefined,
production_date: productionDate || undefined,
shelf_life: composeShelfLifeText(shelfLifeValue, shelfLifeUnit) || undefined,
archive:
buildBatchRowArchive(
{ spec: specInput, origin: originInput },
{ specEdited, originEdited }
) || undefined,
processing_details: processingList,
location: profile?.branch_name || undefined,
watermark_meta: {
@@ -2774,6 +2811,69 @@ export const InspectionManagement: React.FC = () => {
inputClassName="app-input app-focus-ring w-full px-3 py-2 border rounded-md focus:ring-2"
/>
</div>
<div>
<label className="block text-sm text-gray-500 mb-1">{t('inventory.stockIn.phSpec')}</label>
<input
type="text"
value={specInput}
onChange={(event) => {
setSpecInput(event.target.value);
setSpecEdited(true);
}}
disabled={inspectionModalReadonly}
maxLength={60}
className="app-input app-focus-ring w-full px-3 py-2 border rounded-md focus:ring-2"
/>
</div>
<div>
<label className="block text-sm text-gray-500 mb-1">{t('inventory.stockIn.phProdDate')}</label>
<input
type="date"
value={productionDate}
onChange={(event) => setProductionDate(event.target.value)}
disabled={inspectionModalReadonly}
className="app-input app-focus-ring w-full px-3 py-2 border rounded-md focus:ring-2"
/>
</div>
<div>
<label className="block text-sm text-gray-500 mb-1">{t('inventory.stockIn.phShelf')}</label>
<div className="flex items-center gap-2">
<input
type="number"
min={1}
value={shelfLifeValue}
onChange={(event) => setShelfLifeValue(event.target.value)}
disabled={inspectionModalReadonly}
placeholder={t('inspection.qc.shelfValuePh')}
className="app-input app-focus-ring min-w-0 flex-1 px-3 py-2 border rounded-md focus:ring-2"
/>
<select
value={shelfLifeUnit}
onChange={(event) => setShelfLifeUnit(event.target.value)}
disabled={inspectionModalReadonly}
className="app-input app-focus-ring w-24 px-2 py-2 border rounded-md focus:ring-2"
>
<option value="">{t('inspection.qc.shelfUnit')}</option>
<option value="年">{t('inspection.qc.shelfYear')}</option>
<option value="月">{t('inspection.qc.shelfMonth')}</option>
<option value="日">{t('inspection.qc.shelfDay')}</option>
</select>
</div>
</div>
<div>
<label className="block text-sm text-gray-500 mb-1">{t('inventory.stockIn.phOrigin')}</label>
<input
type="text"
value={originInput}
onChange={(event) => {
setOriginInput(event.target.value);
setOriginEdited(true);
}}
disabled={inspectionModalReadonly}
maxLength={60}
className="app-input app-focus-ring w-full px-3 py-2 border rounded-md focus:ring-2"
/>
</div>
</div>
<div className="grid grid-cols-2 gap-3">
{INSPECTION_RESULT_OPTIONS.map((result) => (
@@ -0,0 +1,72 @@
import { readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
/**
* Web 验收(订单入库)弹窗:补 4 字段(规格/生产日期/保质期/产地)+ 修「新建区域后下一单看不到」。
* 设计 docs/design/20261016-订单入库补规格生产日期保质期产地.md(§4-⑥ 原为「Web 另开」,本轮补上)。
*/
const read = (rel: string) => readFileSync(new URL(rel, import.meta.url), 'utf8');
const page = read('./InspectionManagement.tsx');
const types = read('../../utils/inspectionCompliance.types.ts');
const api = read('../../utils/inspectionCompliance.ts');
const wfRoute = read('../../../server/src/modules/workflow/routes/inspectionRoutes.ts');
const listService = read('../../../server/src/services/inspectionQueryService.ts');
describe('Web 验收弹窗:4 字段', () => {
it('规格预填商品库值;四字段状态齐', () => {
expect(page).toContain("setSpecInput(String(task.spec || '').trim());");
expect(page).toContain('const [productionDate, setProductionDate] = useState');
expect(page).toContain('const [shelfLifeValue, setShelfLifeValue] = useState');
expect(page).toContain('const [shelfLifeUnit, setShelfLifeUnit] = useState');
expect(page).toContain('const [originInput, setOriginInput] = useState');
});
it('弹窗渲染四格;保质期 = 数值 + 年/月/日', () => {
expect(page).toContain("t('inventory.stockIn.phSpec')");
expect(page).toContain("t('inventory.stockIn.phProdDate')");
expect(page).toContain("t('inventory.stockIn.phShelf')");
expect(page).toContain("t('inventory.stockIn.phOrigin')");
expect(page).toContain('type="date"');
expect(page).toContain('type="number"');
expect(page).toContain("t('inspection.qc.shelfYear')");
});
it('提交带 production_date / shelf_life(合成原文)/ archive(只回写人工改过的)', () => {
expect(page).toContain('production_date: productionDate || undefined,');
expect(page).toContain(
'shelf_life: composeShelfLifeText(shelfLifeValue, shelfLifeUnit) || undefined,'
);
expect(page).toContain('buildBatchRowArchive(');
});
it('wrapper 类型/接口透传新字段', () => {
expect(types).toContain('shelf_life?: string | null;');
expect(types).toContain('production_date?: string | null;');
expect(types).toContain('archive?:');
expect(api).toContain('shelf_life: input.shelf_life,');
expect(api).toContain('archive: input.archive,');
});
});
describe('Web 验收弹窗:存放区域候选刷新(bug 修复)', () => {
it('提成 loadZoneChoices 并在每次打开弹窗时重拉', () => {
expect(page).toContain('const loadZoneChoices = async () => {');
// 打开入库弹窗时重拉(否则刚建的区域要刷新页面才看得到)
expect(page).toMatch(/void loadZoneChoices\(\);\n };|void loadZoneChoices\(\);/);
expect(page).toContain('每次打开都刷新区域候选');
});
});
describe('后端:Web 路由/列表', () => {
it('workflow 路由透传 shelf_life/archive/production_date', () => {
expect(wfRoute).toContain('shelf_life: req.body?.shelf_life ? String(req.body.shelf_life) : null,');
expect(wfRoute).toContain('archive: req.body?.archive ?? null,');
expect(wfRoute).toContain('production_date: req.body?.production_date ? String(req.body.production_date) : null,');
});
it('Web 列表带出商品库规格', () => {
expect(listService).toContain('sk.spec AS sku_spec,');
expect(listService).toContain('spec: row.sku_spec || null,');
});
});
+3
View File
@@ -17,6 +17,9 @@ export async function submitInspectionCompliance(input: InspectionComplianceInpu
processing_details: input.processing_details,
location: input.location,
storage_zone: input.storage_zone,
production_date: input.production_date,
shelf_life: input.shelf_life,
archive: input.archive,
watermark_meta: input.watermark_meta,
confirm_over_qty: input.confirm_over_qty === true ? true : undefined,
reject_fulfillment: input.reject_fulfillment === true ? true : undefined,
+6
View File
@@ -22,4 +22,10 @@ export interface InspectionComplianceInput {
confirm_over_qty?: boolean;
/** 点「退回」才退供 */
reject_fulfillment?: boolean;
/** 生产日期(YYYY-MM-DD;手填/报告提取) */
production_date?: string | null;
/** 保质期原文(如「6个月」)→ 落 `inventory.shelf_life` 并推算 `expiry_date` */
shelf_life?: string | null;
/** 人工改过的档案字段(规格→product_catalog.spec / 产地→skus.origin);只写传进来的字段 */
archive?: { spec?: string; brand?: string; manufacturer?: string } | null;
}