diff --git a/backend/app/api/budget.py b/backend/app/api/budget.py index ad366ae7..1077eef1 100644 --- a/backend/app/api/budget.py +++ b/backend/app/api/budget.py @@ -220,7 +220,18 @@ def auto_decompose_budget( kpi_version_used[kid] = chosen.version if not kpi_annual: - raise HTTPException(400, "该年度没有可分解的预算,请先在预算执行中录入年度预算") + # 查询该企业有哪些年份有年度预算行(供提示) + from sqlalchemy import distinct + avail_years = [r[0] for r in db.query(distinct(BudgetPlan.budget_year)).filter( + BudgetPlan.entity_id == entity_id, + BudgetPlan.period.like("%-00"), + BudgetPlan.status == "active", + ).order_by(BudgetPlan.budget_year).all()] + hint = f"该年度({year})没有年度预算总额(period=YYYY-00)" + if avail_years: + hint += f";现有年度数据年份:{', '.join(str(y) for y in avail_years)}" + hint += "。请先在预算录入中填写该年度预算总额,或改用战略预算编制按地图录入;如需按已有月度数据反向生成请咨询管理员。" + raise HTTPException(400, hint) results = [] created_count = 0 @@ -293,7 +304,7 @@ def auto_decompose_budget( # ── 单KPI模式(原有逻辑)── if annual_budget is None: - raise HTTPException(400, "缺少必要参数: annual_budget") + raise HTTPException(400, "缺少必要参数: annual_budget(单KPI分解需传年度预算值)") kpi = db.query(KPIDefinition).filter(KPIDefinition.id == kpi_id).first() if not kpi: