fix: patch validation bypass for mandatory inspection

This commit is contained in:
DXC
2026-03-17 13:26:17 +08:00
parent 7829cac59a
commit 11f5a1f51e
2 changed files with 12 additions and 4 deletions

View File

@ -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}】为强管控物料,必须提供检测报告文件或外部链接")