[verified] Implement account valuation history for issue 12

This commit is contained in:
2026-10-06 08:25:43 +00:00
parent 5813dd4841
commit 8df7c26c84
30 changed files with 1950 additions and 121 deletions
+44
View File
@@ -176,6 +176,50 @@ def page_accounts(db_path: str) -> None:
accounts_data = accounts_res.get("accounts", []) if accounts_res.get("success") else []
if accounts_data:
render_account_list(accounts_data)
selected_id = st.selectbox("평가 이력 계좌", [a["id"] for a in accounts_data], format_func=lambda value: next((a.get("name", value) for a in accounts_data if a["id"] == value), value))
selected_account = next(a for a in accounts_data if a["id"] == selected_id)
history = accounts_gateway.list_account_valuations(selected_id, db_path=db_path)
valuations = history.get("valuations", []) if history.get("success") else []
if valuations:
st.dataframe(valuations, width="stretch", hide_index=True)
# The list is historical insertion order; a rejected/corrected
# tail is not necessarily the effective current valuation.
basis = (selected_account.get("last_synced_at") or "")[:10]
selected = accounts_gateway.select_account_valuation(selected_id, basis, as_of=True, db_path=db_path) if basis else {}
selected_valuation = selected.get("valuation") if selected.get("success") else None
latest = selected_valuation or next(
(item for item in reversed(valuations) if item.get("verification_status") == "verified"), valuations[-1]
)
st.caption(f"최근 실제 기준일: {latest.get('basis_date', '-')} · 상태: {latest.get('verification_status', 'unknown')} · 종류: {latest.get('valuation_kind', 'unknown')}")
else:
st.warning("평가 이력이 없습니다.")
with st.expander("계좌 평가 등록"):
with st.form(f"account_valuation_register_{selected_id}"):
v_date = st.text_input("평가 기준일", value=selected_account.get("last_synced_at", "")[:10])
v_amount = st.number_input("평가 금액", value=int(selected_account.get("last_balance") or 0), step=1)
default_kind = "loan_balance" if selected_account.get("type") == "loan" else ("total_value" if selected_account.get("type") == "investment" else "cash_balance")
v_kind = st.selectbox("평가 종류", ["cash_balance", "balance", "total_value", "loan_balance", "loan"], index=["cash_balance", "balance", "total_value", "loan_balance", "loan"].index(default_kind))
v_status = st.selectbox("검증 상태", ["unverified", "verified", "rejected"])
v_definition = st.selectbox("대표 부채 정의(대출 필수)", ["", "principal_only", "principal_interest_fees"])
v_submit = st.form_submit_button("평가 등록")
if v_submit:
result = accounts_gateway.register_account_valuation(selected_id, v_date, int(v_amount), valuation_kind=v_kind, verification_status=v_status, representative_liability_definition=v_definition or None, db_path=db_path)
if result.get("success"):
clear_cache(); st.success("평가를 등록했습니다."); st.rerun()
else:
st.error(result.get("error", result))
with st.expander("계좌 평가 정정"):
with st.form(f"account_valuation_correct_{selected_id}"):
correction_id = st.text_input("정정 대상 평가 ID")
correction_amount = st.number_input("정정 금액", value=0, step=1, key=f"correction_amount_{selected_id}")
correction_reason = st.text_input("정정 사유")
correction_submit = st.form_submit_button("평가 정정")
if correction_submit:
result = accounts_gateway.correct_account_valuation(correction_id, int(correction_amount), correction_reason, db_path=db_path)
if result.get("success"):
clear_cache(); st.success("평가를 정정했습니다."); st.rerun()
else:
st.error(result.get("error", result))
account_edit_id = st.session_state.get("account_edit_id")
if account_edit_id:
account = next((item for item in accounts_data if item["id"] == account_edit_id), None)