fix: classify conditional previews and normalize currency
This commit is contained in:
@@ -92,7 +92,7 @@ def _account_valuation_items(conn: sqlite3.Connection, basis_date: str = "", sel
|
||||
if basis_date:
|
||||
valuation_rows = conn.execute(
|
||||
"SELECT * FROM account_valuations WHERE account_id=? AND currency=? ORDER BY basis_date DESC, recorded_at DESC, id DESC",
|
||||
(account["id"], account.get("currency") or "KRW"),
|
||||
(account["id"], base["currency"]),
|
||||
).fetchall()
|
||||
leaves = [v for v in valuation_rows if conn.execute("SELECT 1 FROM account_valuations WHERE supersedes_id=?", (v["id"],)).fetchone() is None]
|
||||
if account_type == "investment":
|
||||
@@ -427,8 +427,15 @@ def preview_asset_snapshot_close(basis_date: str = "", db_path: str | None = Non
|
||||
with db(db_path) as conn:
|
||||
preview = _snapshot_preview_from_conn(conn, basis, selection_policy)
|
||||
preview["selection_policy"] = selection_policy
|
||||
blocking = [w for w in preview["warnings"] if w.get("blocking", True) and w.get("code", "").startswith(("missing_", "future_", "unknown_", "unverified", "ambiguous_", "stale_"))]
|
||||
preview["close_status"] = "complete_exact" if selection_policy == "exact" and not blocking else "incomplete_draft"
|
||||
approval_eligible = [w for w in preview["warnings"] if w.get("blocking", True) and w.get("code", "").startswith(("missing_", "future_", "unknown_", "unverified", "ambiguous_"))]
|
||||
carried_items = [item for item in preview["included_items"] if item.get("carried_forward")]
|
||||
other_blocking = [w for w in preview["warnings"] if w.get("blocking", True) and w.get("code", "").startswith("stale_") and not carried_items]
|
||||
if other_blocking:
|
||||
preview["close_status"] = "incomplete_draft"
|
||||
elif approval_eligible or carried_items:
|
||||
preview["close_status"] = "conditional"
|
||||
else:
|
||||
preview["close_status"] = "complete_exact"
|
||||
preview.pop("_candidate_state_hashes", None)
|
||||
return ok(**preview)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user