Fix loan account conversion invariant
This commit is contained in:
@@ -62,6 +62,16 @@ def update_ledger_account(account_id: str, db_path: str | None = None, **fields:
|
||||
except Exception as e: return fail("validation_error", str(e))
|
||||
updates.append(f"{k}=?"); params.append(v)
|
||||
if not updates: return fail("validation_error", "no fields to update")
|
||||
target_type = fields.get("type", current["type"])
|
||||
if str(current["type"]).lower() != "loan" and target_type == "loan":
|
||||
invalid_valuation = conn.execute(
|
||||
"SELECT 1 FROM account_valuations "
|
||||
"WHERE account_id=? AND (representative_liability_definition IS NULL "
|
||||
"OR representative_liability_definition NOT IN (?, ?)) LIMIT 1",
|
||||
(account_id, "principal_only", "principal_interest_fees"),
|
||||
).fetchone()
|
||||
if invalid_valuation is not None:
|
||||
return fail("validation_error", "loan account requires a valid representative liability definition for every valuation")
|
||||
stored_date = str(current["last_balance_basis_date"] or "")[:10]
|
||||
incoming_date = normalized_basis if basis_update else ""
|
||||
historical = bool(balance_update and incoming_date and stored_date and incoming_date < stored_date)
|
||||
|
||||
Reference in New Issue
Block a user