fix: 年份动态计算 + 首页布局优化
- 后端所有硬编码2026替换为date.today().year动态计算 - 首页移除4个快捷跳转卡片 - 首页新增时间段筛选下拉框 - 版本号更新至v1.0.0.3
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# 依赖:db.py;被 routes.py 和 migrations/seed_data.py 调用
|
||||
|
||||
import json
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
from db import _exec, rows, one
|
||||
|
||||
@@ -61,7 +62,8 @@ def attach_common(conn, resource, items):
|
||||
|
||||
|
||||
def monthly_finance(conn, tenant="科普·无界"):
|
||||
months = [f"2026-{m:02d}" for m in range(1, 13)]
|
||||
_year = date.today().year
|
||||
months = [f"{_year}-{m:02d}" for m in range(1, 13)]
|
||||
pfs = rows(conn,
|
||||
"SELECT sign_amount, sign_month, status, budget_data, expense_data FROM project_finances WHERE tenant=? AND status='已签约'",
|
||||
[tenant])
|
||||
|
||||
@@ -228,6 +228,7 @@ def index():
|
||||
def bootstrap():
|
||||
if "user_id" not in session:
|
||||
return jsonify({"error": "未登录"}), 401
|
||||
_year = date.today().year
|
||||
tenant = request.args.get("tenant", session.get("tenants", ["科普·无界"])[0])
|
||||
allowed = session.get("tenants", [])
|
||||
if "总工作台" not in allowed:
|
||||
@@ -262,7 +263,7 @@ def bootstrap():
|
||||
for pf in t_pfs:
|
||||
bm = t_bm.get(pf["id"], {})
|
||||
for m in months_range:
|
||||
b = bm.get(f"2026_{m:02d}")
|
||||
b = bm.get(f"{_year}_{m:02d}")
|
||||
if b:
|
||||
total += float(b.get(field) or 0)
|
||||
return total
|
||||
@@ -281,7 +282,7 @@ def bootstrap():
|
||||
for pf in t_pfs:
|
||||
em = t_em.get(pf["id"], {})
|
||||
for m in months_range:
|
||||
e = em.get(f"2026_{m:02d}")
|
||||
e = em.get(f"{_year}_{m:02d}")
|
||||
if e:
|
||||
total += float(e.get(field) or 0)
|
||||
return total
|
||||
@@ -289,10 +290,10 @@ def bootstrap():
|
||||
_now_month = date.today().month
|
||||
_q_start = ((_now_month - 1) // 3) * 3 + 1
|
||||
_q_range = range(_q_start, _q_start + 3)
|
||||
_q_months = [f"2026-{m:02d}" for m in _q_range]
|
||||
_q_months = [f"{_year}-{m:02d}" for m in _q_range]
|
||||
_prev_q_start = ((_now_month - 4) // 3) * 3 + 1
|
||||
_prev_q_range = range(max(_prev_q_start, 1), _prev_q_start + 3)
|
||||
_prev_q_months = [f"2026-{m:02d}" for m in _prev_q_range]
|
||||
_prev_q_months = [f"{_year}-{m:02d}" for m in _prev_q_range]
|
||||
_prev_month = _now_month - 1 if _now_month > 1 else None
|
||||
all_metrics.append({
|
||||
"total_projects": len(t_signed_pfs),
|
||||
@@ -302,9 +303,9 @@ def bootstrap():
|
||||
"signed_amount": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约"),
|
||||
"signed_annual": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约"),
|
||||
"signed_q2": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _q_months),
|
||||
"signed_month": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"2026-{_now_month:02d}"),
|
||||
"signed_month": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_now_month:02d}"),
|
||||
"signed_prev_q": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _prev_q_months),
|
||||
"signed_prev_month": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"2026-{_prev_month:02d}") if _prev_month else 0,
|
||||
"signed_prev_month": sum(x["sign_amount"] or 0 for x in t_pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_prev_month:02d}") if _prev_month else 0,
|
||||
"revenue_annual": t_sum_budget("rev", range(1, 13)),
|
||||
"revenue_q2": t_sum_budget("rev", _q_range),
|
||||
"monthly_revenue": t_sum_budget("rev", [_now_month]),
|
||||
@@ -369,7 +370,7 @@ def bootstrap():
|
||||
agg[key] = sum(m.get(key, 0) for m in all_metrics)
|
||||
merged_monthly = []
|
||||
for i in range(12):
|
||||
m = {"month": all_monthly[0][i]["month"] if all_monthly and len(all_monthly[0]) > i else f"2026-{i+1:02d}"}
|
||||
m = {"month": all_monthly[0][i]["month"] if all_monthly and len(all_monthly[0]) > i else f"{_year}-{i+1:02d}"}
|
||||
for field in ["revenue","gross","payment","cost","paid","sign"]:
|
||||
m[field] = sum(tl[i][field] if i < len(tl) else 0 for tl in all_monthly)
|
||||
merged_monthly.append(m)
|
||||
@@ -415,7 +416,7 @@ def bootstrap():
|
||||
total = 0
|
||||
for pf, bm in budget_maps:
|
||||
for m in months_range:
|
||||
b = bm.get(f"2026_{m:02d}")
|
||||
b = bm.get(f"{_year}_{m:02d}")
|
||||
if b:
|
||||
total += float(b.get(field) or 0)
|
||||
return total
|
||||
@@ -424,7 +425,7 @@ def bootstrap():
|
||||
total = 0
|
||||
for pf, em in expense_maps:
|
||||
for m in months_range:
|
||||
e = em.get(f"2026_{m:02d}")
|
||||
e = em.get(f"{_year}_{m:02d}")
|
||||
if e:
|
||||
total += float(e.get(field) or 0)
|
||||
return total
|
||||
@@ -494,12 +495,12 @@ def bootstrap():
|
||||
return sum(x["sign_amount"] or 0 for x in pfs if x["status"] == status)
|
||||
signed_amount = pf_status_sum("已签约")
|
||||
signed_annual = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约")
|
||||
_q_months = [f"2026-{m:02d}" for m in _q_range]
|
||||
_q_months = [f"{_year}-{m:02d}" for m in _q_range]
|
||||
signed_q2 = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _q_months)
|
||||
signed_month = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"2026-{_now_month:02d}")
|
||||
_prev_q_months = [f"2026-{m:02d}" for m in _prev_q_range]
|
||||
signed_month = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_now_month:02d}")
|
||||
_prev_q_months = [f"{_year}-{m:02d}" for m in _prev_q_range]
|
||||
signed_prev_q = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] in _prev_q_months)
|
||||
signed_prev_month = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"2026-{_prev_month:02d}") if _prev_month else 0
|
||||
signed_prev_month = sum(x["sign_amount"] or 0 for x in pfs if x["status"] == "已签约" and (x.get("sign_month") or "")[:7] == f"{_year}-{_prev_month:02d}") if _prev_month else 0
|
||||
pipeline_amount = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_status"] not in ["已签约","已丢单","已归档","已完成"])
|
||||
signed_not_executed = sum(x["expected_contract_amount"] or 0 for x in operations if x["project_type"] == "execution" and x["execution_progress"] < 100)
|
||||
summary = {
|
||||
|
||||
Reference in New Issue
Block a user