fix: preserve schema 15 compatibility for v0.1.8

This commit is contained in:
2026-10-17 18:27:53 +09:00
parent a97548c36b
commit 1134f058cc
61 changed files with 2650 additions and 644 deletions
+45 -1
View File
@@ -31,6 +31,39 @@ def _authenticated_actor() -> str | None:
return get_authenticated_actor()
def _open_settlement_history(draft_id: str, run_id: str = "") -> None:
"""Open the read-only history panel and prefer the completed draft's run."""
st.session_state["settlement_history_open_draft"] = draft_id
if run_id:
st.session_state[f"settlement_history_run_{draft_id}"] = run_id
def _render_settlement_history(db_path: str | None, month: str, draft_id: str) -> None:
"""List immutable runs and fetch the exact record selected by the operator."""
listed = gateway.list_monthly_settlement_history(month, db_path=db_path)
if not listed.get("success"):
st.error(f"마감 이력을 불러오지 못했습니다 ({listed.get('error_code', 'operation_failed')}).")
return
history = listed.get("history", [])
if not isinstance(history, list):
history = []
runs = [str(item.get("run_id")) for item in history if isinstance(item, dict) and item.get("run_id")]
if not runs:
st.info("저장된 불변 마감 이력이 없습니다.")
return
selection_key = f"settlement_history_run_{draft_id}"
if st.session_state.get(selection_key) not in runs:
st.session_state[selection_key] = runs[0]
selected_run = st.selectbox("불변 마감 run 선택", runs, key=selection_key)
st.dataframe(history, hide_index=True, use_container_width=True)
record = gateway.get_monthly_settlement_history_record(selected_run, db_path=db_path)
if not record.get("success"):
st.error(f"마감 기록을 불러오지 못했습니다 ({record.get('error_code', 'operation_failed')}).")
return
st.caption("선택한 run의 저장 시점 불변 기록")
st.json(record.get("history", {}))
def _create_settlement_dialog(db_path: str | None, month: str, correction_run: str = "") -> None:
@st.dialog("정산 진행")
def dialog() -> None:
@@ -66,7 +99,6 @@ def _create_settlement_dialog(db_path: str | None, month: str, correction_run: s
result = gateway.create_settlement_draft(target_month, actor, key, memo=memo,
correction_of_run_id=correction_run, correction_reason=reason, db_path=db_path)
if result.get("success"):
created_id = (result.get("draft") or {}).get("id", "")
# The selectbox is the authoritative selection on the next
# rerun; seed its widget state, not a separate shadow key.
st.query_params["page"] = "월정산"
@@ -147,6 +179,18 @@ def render_settlement_drafts(db_path: str | None = None, month: str = "") -> Non
st.write(label, final.get(key) if final.get(key) is not None else "미보존")
rows = final.get("cashflow_items", [])
if isinstance(rows, list): st.dataframe([{k: row.get(k) for k in ("cashflow_kind", "category", "subcategory", "amount", "transaction_count", "currency")} for row in rows if isinstance(row, dict)])
st.markdown("### 불변 이력")
st.write("final_run_id", draft.get("final_run_id"))
st.write("correction_of_run_id", draft.get("correction_of_run_id"))
st.json(detail.get("items", []))
st.button(
"마감내역보기",
key=f"closed_history_{selected_id}",
on_click=_open_settlement_history,
args=(selected_id, str(draft.get("final_run_id") or "")),
)
if st.session_state.get("settlement_history_open_draft") == selected_id:
_render_settlement_history(db_path, str(draft.get("month") or month_value), selected_id)
if draft.get("final_run_id") and st.button("정정시작", disabled=not actor, key=f"correction_start_{selected_id}"):
_create_settlement_dialog(db_path, draft.get("month", month_value), str(draft["final_run_id"]))
st.caption("종료된 초안의 증거는 수정하지 않습니다. 정정이 필요하면 이전 마감과 사유를 연결해 새 초안을 생성하세요.")