Refactor logging and transaction time normalization: Updated the get_client_balance_summary function to use loguru for improved logging clarity. Enhanced transaction processing to normalize transaction_time to UTC, ensuring consistency and accuracy in time handling across transactions.
This commit is contained in:
parent
5988a25983
commit
3e4effb76f
2 changed files with 9 additions and 1 deletions
2
crud.py
2
crud.py
|
|
@ -264,7 +264,7 @@ async def get_client_balance_summary(client_id: str, as_of_time: Optional[dateti
|
|||
|
||||
# Log temporal filtering if as_of_time was used
|
||||
if as_of_time is not None:
|
||||
from lnbits.core.services import logger
|
||||
from loguru import logger
|
||||
# Verify timezone consistency for temporal filtering
|
||||
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}): deposits.confirmed_at <= cutoff, payments.transaction_time <= cutoff → {total_deposits - total_payments} centavos remaining")
|
||||
|
|
|
|||
|
|
@ -902,6 +902,14 @@ class LamassuTransactionProcessor:
|
|||
fiat_amount = transaction.get("fiat_amount", 0)
|
||||
commission_percentage = transaction.get("commission_percentage") or 0.0
|
||||
discount = transaction.get("discount") or 0.0
|
||||
transaction_time = transaction.get("transaction_time")
|
||||
|
||||
# Normalize transaction_time to UTC if present
|
||||
if transaction_time is not None:
|
||||
if transaction_time.tzinfo is None:
|
||||
transaction_time = transaction_time.replace(tzinfo=timezone.utc)
|
||||
elif transaction_time.tzinfo != timezone.utc:
|
||||
transaction_time = transaction_time.astimezone(timezone.utc)
|
||||
|
||||
# Calculate commission metrics
|
||||
if commission_percentage > 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue