Fix: Eagerly load bet_details to fix total_payout calculation

- Add joinedload for bet_details relationship when querying bets
- This ensures bet_details are loaded for ALL bets, not just synced ones
- Fixes total_payout showing 0 when there are winning bets
- Summary is calculated from ALL bets (synced and not synced) as required for server reports
parent 2ee7f304
...@@ -1046,6 +1046,7 @@ class ReportsSyncResponseHandler(ResponseHandler): ...@@ -1046,6 +1046,7 @@ class ReportsSyncResponseHandler(ResponseHandler):
) )
from datetime import datetime, timedelta, date from datetime import datetime, timedelta, date
import hashlib import hashlib
from sqlalchemy.orm import joinedload
# Determine date range # Determine date range
now = datetime.utcnow() now = datetime.utcnow()
...@@ -1081,7 +1082,10 @@ class ReportsSyncResponseHandler(ResponseHandler): ...@@ -1081,7 +1082,10 @@ class ReportsSyncResponseHandler(ResponseHandler):
logger.info(f"Full sync: collecting all data (no previous sync found)") logger.info(f"Full sync: collecting all data (no previous sync found)")
# Collect bets data (incremental - only new/updated bets) # Collect bets data (incremental - only new/updated bets)
bets_query = session.query(BetModel).filter( # Eagerly load bet_details to avoid lazy loading issues
bets_query = session.query(BetModel).options(
joinedload(BetModel.bet_details)
).filter(
BetModel.bet_datetime >= start_date, BetModel.bet_datetime >= start_date,
BetModel.bet_datetime <= end_date BetModel.bet_datetime <= end_date
) )
...@@ -1162,7 +1166,7 @@ class ReportsSyncResponseHandler(ResponseHandler): ...@@ -1162,7 +1166,7 @@ class ReportsSyncResponseHandler(ResponseHandler):
'bets': [], 'bets': [],
'extraction_stats': [], 'extraction_stats': [],
'cap_compensation_balance': cap_compensation_balance, 'cap_compensation_balance': cap_compensation_balance,
'summary': self._calculate_summary(bets, stats), # Use ALL bets and stats for summary, not just synced ones 'summary': self._calculate_summary(bets_to_sync, stats), # Use bets_to_sync which have bet_details loaded
'is_incremental': True, # Flag to indicate this is an incremental sync 'is_incremental': True, # Flag to indicate this is an incremental sync
'sync_type': 'incremental' if last_sync_time else 'full' 'sync_type': 'incremental' if last_sync_time else 'full'
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment