fix: prevent inbound of disabled materials

This commit is contained in:
dxc
2026-02-10 13:50:26 +08:00
committed by dxc (aider)
parent 18da3979a9
commit 17a61b489c
4 changed files with 30 additions and 7 deletions

View File

@ -40,7 +40,7 @@ class ProductInboundService:
@staticmethod
def search_base_material(keyword):
try:
# 1. 基础查询:必须是已启用的物料
# [核心修改] 只查询已启用的物料
query = MaterialBase.query.filter(MaterialBase.is_enabled == True)
# 2. 动态条件:如果传入了关键词,则增加模糊匹配条件
@ -85,6 +85,10 @@ class ProductInboundService:
material = MaterialBase.query.get(base_id)
if not material: raise ValueError("物料不存在")
# [核心修改] 后端二次校验:如果物料已停用,禁止入库
if not material.is_enabled:
raise ValueError(f"物料【{material.name}】已停用,无法办理新入库。")
# --- [核心修改] 执行唯一性校验 ---
ProductInboundService._check_unique(
serial_number=data.get('serial_number')