fix: address account valuation review findings
This commit is contained in:
@@ -43,19 +43,10 @@ def _record_import_valuation_candidate(conn: Any, account_id: str, balance: Any,
|
||||
def _update_current_balance_if_newer(conn: Any, account_id: str, balance: Any, basis_date: str, synced_at: str) -> None:
|
||||
if balance is None or not basis_date:
|
||||
return
|
||||
current = conn.execute("SELECT last_synced_at FROM accounts WHERE id=?", (account_id,)).fetchone()
|
||||
latest_evidence = conn.execute(
|
||||
"""SELECT basis_date FROM account_valuations
|
||||
WHERE account_id=? AND verification_status IN ('verified', 'unverified')
|
||||
ORDER BY basis_date DESC, recorded_at DESC, id DESC LIMIT 1""",
|
||||
(account_id,),
|
||||
).fetchone()
|
||||
current_date = max(
|
||||
str(current["last_synced_at"] or "")[:10] if current else "",
|
||||
str(latest_evidence["basis_date"] or "")[:10] if latest_evidence else "",
|
||||
)
|
||||
current = conn.execute("SELECT last_balance_basis_date FROM accounts WHERE id=?", (account_id,)).fetchone()
|
||||
current_date = str(current["last_balance_basis_date"] or "")[:10] if current else ""
|
||||
if not current_date or basis_date[:10] >= current_date:
|
||||
conn.execute("UPDATE accounts SET last_balance=?, last_synced_at=?, updated_at=? WHERE id=?", (balance, synced_at, synced_at, account_id))
|
||||
conn.execute("UPDATE accounts SET last_balance=?, last_balance_basis_date=?, last_synced_at=?, updated_at=? WHERE id=?", (balance, basis_date[:10], synced_at, synced_at, account_id))
|
||||
|
||||
@read_operation
|
||||
def preview_ledger_csv_import(file_path: str, source: str = "generic", db_path: str | None = None) -> dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user