diff --git a/backend/app/api/reports.py b/backend/app/api/reports.py index 5f64fa63..5fedd5a0 100644 --- a/backend/app/api/reports.py +++ b/backend/app/api/reports.py @@ -2414,11 +2414,15 @@ def get_dupont_analysis( roe_exact = f_ann.get("roe") roe_change = None if (roe_exact is None or prev_roe is None) else round(roe_exact - prev_roe, 4) + def _fmt(v): + # 存量/流量缺失时 raw 值为 None(如博海存量仅到区间外)⇒ 显式「-」,不得 None 格式化 + return "-" if v is None else f"{v:.2f}" + detail = (f"{label}口径(流量累计 {win['period_start']}~{win['period_end']}," f"存量{'平均' if cur['basis'] == 'average' else '期末回落'}" f"{',年化 ×12/' + str(win['months']) if annualize else ',非年化'}):" - f"净利润 {cur['raw']['net_profit']:.2f}万 / 营业收入 {cur['raw']['revenue']:.2f}万 / " - f"平均总资产 {cur['raw']['total_assets']:.2f}万 / 平均净资产 {cur['raw']['equity']:.2f}万;" + f"净利润 {_fmt(cur['raw']['net_profit'])}万 / 营业收入 {_fmt(cur['raw']['revenue'])}万 / " + f"平均总资产 {_fmt(cur['raw']['total_assets'])}万 / 平均净资产 {_fmt(cur['raw']['equity'])}万;" f"ROE = {factors['net_profit_margin']['value']}% × {factors['asset_turnover']['value']} × " f"{factors['equity_multiplier']['value']} = {None if roe_exact is None else round(roe_exact, 2)}%" f"(恒等式 {'通过' if identity.get('status') == 'pass' else identity.get('status')},"