Refine client balance summary logic: Updated the get_client_balance_summary function to filter payments based on transaction_time for improved temporal accuracy. Enhanced logging to clarify balance calculations with respect to the cutoff time, ensuring better transparency in reported balances.
This commit is contained in:
parent
59e4d53215
commit
5988a25983
1 changed files with 8 additions and 3 deletions
11
crud.py
11
crud.py
|
|
@ -243,12 +243,17 @@ async def get_client_balance_summary(client_id: str, as_of_time: Optional[dateti
|
||||||
params
|
params
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get total payments made (only those created before the cutoff time)
|
# Get total payments made (only those with ATM transaction time before the cutoff)
|
||||||
|
# Use transaction_time instead of created_at for temporal accuracy
|
||||||
|
payment_time_filter = ""
|
||||||
|
if as_of_time is not None:
|
||||||
|
payment_time_filter = "AND transaction_time <= :as_of_time"
|
||||||
|
|
||||||
total_payments_result = await db.fetchone(
|
total_payments_result = await db.fetchone(
|
||||||
f"""
|
f"""
|
||||||
SELECT COALESCE(SUM(amount_fiat), 0) as total
|
SELECT COALESCE(SUM(amount_fiat), 0) as total
|
||||||
FROM satoshimachine.dca_payments
|
FROM satoshimachine.dca_payments
|
||||||
WHERE client_id = :client_id AND status = 'confirmed' {time_filter}
|
WHERE client_id = :client_id AND status = 'confirmed' {payment_time_filter}
|
||||||
""",
|
""",
|
||||||
params
|
params
|
||||||
)
|
)
|
||||||
|
|
@ -262,7 +267,7 @@ async def get_client_balance_summary(client_id: str, as_of_time: Optional[dateti
|
||||||
from lnbits.core.services import logger
|
from lnbits.core.services import logger
|
||||||
# Verify timezone consistency for temporal filtering
|
# Verify timezone consistency for temporal filtering
|
||||||
tz_info = "UTC" if as_of_time.tzinfo == timezone.utc else f"TZ: {as_of_time.tzinfo}"
|
tz_info = "UTC" if as_of_time.tzinfo == timezone.utc else f"TZ: {as_of_time.tzinfo}"
|
||||||
logger.info(f"Client {client_id[:8]}... balance as of {as_of_time} ({tz_info}): {total_deposits - total_payments} centavos remaining")
|
logger.info(f"Client {client_id[:8]}... balance as of {as_of_time} ({tz_info}): deposits.confirmed_at <= cutoff, payments.transaction_time <= cutoff → {total_deposits - total_payments} centavos remaining")
|
||||||
|
|
||||||
return ClientBalanceSummary(
|
return ClientBalanceSummary(
|
||||||
client_id=client_id,
|
client_id=client_id,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue