[verified] Implement account valuation history for issue 12
This commit is contained in:
@@ -86,6 +86,24 @@ def get_balance_reconciliation_report(account_id: str = "", baseline_balance: in
|
||||
effective_baseline = baseline_balance_int if baseline_balance_int is not None else account["last_balance"]
|
||||
effective_at = baseline_at_norm or account["last_synced_at"] or now_iso()
|
||||
calc = _account_balance_row(conn, account["id"], effective_at)
|
||||
valuation = conn.execute(
|
||||
"""SELECT * FROM account_valuations v
|
||||
WHERE v.account_id=? AND v.verification_status='verified'
|
||||
AND v.basis_date<=?
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM account_valuations child
|
||||
WHERE child.supersedes_id=v.id
|
||||
)
|
||||
ORDER BY CASE v.valuation_kind
|
||||
WHEN 'total_value' THEN 0
|
||||
WHEN 'balance' THEN 1
|
||||
WHEN 'cash_balance' THEN 2
|
||||
ELSE 3
|
||||
END,
|
||||
v.basis_date DESC, v.recorded_at DESC, v.id DESC
|
||||
LIMIT 1""",
|
||||
(account["id"], effective_at[:10]),
|
||||
).fetchone()
|
||||
if effective_baseline is None:
|
||||
difference = None
|
||||
ratio = None
|
||||
@@ -94,6 +112,9 @@ def get_balance_reconciliation_report(account_id: str = "", baseline_balance: in
|
||||
difference = int(effective_baseline) - int(calc["calculated_balance"])
|
||||
ratio = abs(difference) / abs(int(effective_baseline)) if int(effective_baseline) else None
|
||||
status = "OK" if abs(difference) <= tolerance_int else "REVIEW_NEEDED"
|
||||
if account["type"] == "investment" and valuation is not None:
|
||||
status = "VALUATION_MANAGED"
|
||||
difference = None
|
||||
items.append({
|
||||
"account_id": account["id"],
|
||||
"account_name": account["name"],
|
||||
@@ -107,6 +128,9 @@ def get_balance_reconciliation_report(account_id: str = "", baseline_balance: in
|
||||
"reference_ratio_threshold": BALANCE_RECONCILIATION_REFERENCE_RATIO,
|
||||
"difference_ratio": ratio,
|
||||
"status": status,
|
||||
"external_confirmed_value": int(valuation["amount"]) if valuation is not None else None,
|
||||
"valuation_id": valuation["id"] if valuation is not None else "",
|
||||
"valuation_kind": valuation["valuation_kind"] if valuation is not None else "",
|
||||
"recommended_decisions": ["계좌이동", "실지출", "실수입", "투자이동", "분석제외", "확인필요"] if status == "REVIEW_NEEDED" else [],
|
||||
"reconciliation_session": latest_sessions.get(account["id"]),
|
||||
"review_status": latest_decisions.get(("reconciliation_account", account["id"]), {}).get("status", "pending"),
|
||||
|
||||
Reference in New Issue
Block a user