fix: preserve snapshot compatibility and loan fallback
This commit is contained in:
@@ -79,10 +79,12 @@ def _validate_common(account_id: str, basis_date: str, amount: int, currency: st
|
||||
if source not in _VALID_SOURCE_TYPES:
|
||||
return fail("validation_error", f"source_type must be one of {sorted(_VALID_SOURCE_TYPES)}")
|
||||
definition = representative_liability_definition.strip() if representative_liability_definition else None
|
||||
if kind in {"loan", "loan_balance"} and definition not in _VALID_LOAN_DEFINITIONS:
|
||||
if definition is not None and definition not in _VALID_LOAN_DEFINITIONS:
|
||||
return fail("validation_error", "representative liability definition is invalid")
|
||||
if kind in {"loan", "loan_balance"} and definition is None:
|
||||
return fail("validation_error", "loan valuation requires representative_liability_definition")
|
||||
if kind not in {"loan", "loan_balance"} and definition is not None:
|
||||
return fail("validation_error", "non-loan valuation cannot define representative liability")
|
||||
if kind not in {"loan", "loan_balance", "balance"} and definition is not None:
|
||||
return fail("validation_error", "valuation kind cannot define representative liability")
|
||||
if amount_int is None:
|
||||
return fail("validation_error", "amount must be an integer")
|
||||
return basis, amount_int, currency_norm, status, source, definition
|
||||
@@ -182,6 +184,8 @@ def register_account_valuation(
|
||||
return fail("validation_error", "valuation currency must match account currency")
|
||||
if (valuation_kind or "balance").strip().lower() in {"loan", "loan_balance"} and str(account["type"]).lower() != "loan":
|
||||
return fail("validation_error", "loan valuation kind requires a loan account")
|
||||
if definition is not None and str(account["type"]).lower() != "loan":
|
||||
return fail("validation_error", "representative liability definition requires a loan account")
|
||||
if idempotency_key:
|
||||
existing = conn.execute("SELECT * FROM account_valuations WHERE account_id=? AND idempotency_key=?", (account_id, idempotency_key)).fetchone()
|
||||
if existing:
|
||||
|
||||
Reference in New Issue
Block a user