From 11f5a1f51e6dbbedb8bb7036f31e8a6e0dc42e45 Mon Sep 17 00:00:00 2001 From: DXC Date: Tue, 17 Mar 2026 13:26:17 +0800 Subject: [PATCH] fix: patch validation bypass for mandatory inspection --- .../app/services/inbound/buy_service.py | 12 +++++++++--- inventory-web/src/views/stock/inbound/buy.vue | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/inventory-backend/app/services/inbound/buy_service.py b/inventory-backend/app/services/inbound/buy_service.py index 027cdbc..a9bb39a 100644 --- a/inventory-backend/app/services/inbound/buy_service.py +++ b/inventory-backend/app/services/inbound/buy_service.py @@ -105,7 +105,9 @@ class BuyInboundService: # 检查检测报告:文件列表或外部链接至少有一个 # 前端会将外部链接添加到 inspection_report 数组中一起提交 inspection_report_list = data.get('inspection_report', []) - has_report_file = inspection_report_list and len(inspection_report_list) > 0 + # 过滤空字符串,只保留有效报告(字符串长度 > 0 且去除空格后非空) + valid_reports = [r for r in inspection_report_list if r and str(r).strip()] + has_report_file = valid_reports and len(valid_reports) > 0 if not has_report_file: raise ValueError(f"物料【{material.name}】为强管控物料,必须提供检测报告文件或外部链接") @@ -209,9 +211,13 @@ class BuyInboundService: existing_reports = json_module.loads(stock.inspection_report) if stock.inspection_report else [] except: existing_reports = [] - has_report_file = existing_reports and len(existing_reports) > 0 + # 过滤空字符串,只保留有效报告 + valid_reports = [r for r in existing_reports if r and str(r).strip()] + has_report_file = valid_reports and len(valid_reports) > 0 else: - has_report_file = inspection_report_list and len(inspection_report_list) > 0 + # 过滤空字符串,只保留有效报告 + valid_reports = [r for r in inspection_report_list if r and str(r).strip()] + has_report_file = valid_reports and len(valid_reports) > 0 if not has_report_file: raise ValueError(f"物料【{material.name}】为强管控物料,必须提供检测报告文件或外部链接") diff --git a/inventory-web/src/views/stock/inbound/buy.vue b/inventory-web/src/views/stock/inbound/buy.vue index d11f594..c7f08d6 100644 --- a/inventory-web/src/views/stock/inbound/buy.vue +++ b/inventory-web/src/views/stock/inbound/buy.vue @@ -1194,7 +1194,9 @@ const rules = computed(() => { baseRules.inspection_report = [ { validator: (rule: any, value: any, callback: any) => { - const hasFile = form.inspection_report && form.inspection_report.length > 0 + // 过滤空字符串,只保留有效报告 + const validFiles = (form.inspection_report || []).filter((r: string) => r && r.trim()) + const hasFile = validFiles.length > 0 const hasLink = inspection_report_url.value && inspection_report_url.value.trim() !== '' if (!hasFile && !hasLink) { callback(new Error('该物料为强管控物料,必须提供检测报告文件或链接'))