Commit 3fdad329 authored by Your Name's avatar Your Name

Clarify sync carryover reporting

parent 27b5028b
......@@ -1155,7 +1155,7 @@ class ReportsSyncResponseHandler(ResponseHandler):
'extraction_stats': [],
'cap_compensation_balance': cap_compensation_balance,
'global_carryover_balance': cap_compensation_balance,
'summary': self._calculate_summary(bets_to_sync, stats), # Use bets_to_sync which have bet_details loaded
'summary': self._calculate_summary(bets_to_sync, stats_to_sync),
'is_incremental': True, # Flag to indicate this is an incremental sync
'sync_type': 'incremental' if last_sync_time else 'full'
}
......
from pathlib import Path
from types import SimpleNamespace
from datetime import datetime, date
from mbetterclient.api_client.client import ReportsSyncResponseHandler
from mbetterclient.core.message_bus import MessageBus
from mbetterclient.database.manager import DatabaseManager
from mbetterclient.database.models import BetDetailModel, BetModel
from mbetterclient.database.models import BetDetailModel, BetModel, MatchModel, ExtractionStatsModel, PersistentRedistributionAdjustmentModel
def _build_handler(tmp_path: Path):
......@@ -57,3 +58,75 @@ def test_calculate_summary_payload_can_carry_global_balance_separately(tmp_path)
assert summary['total_matches'] == 0
finally:
db_manager.close()
def test_collect_report_data_separates_daily_summary_and_global_carryover(tmp_path):
handler, db_manager = _build_handler(tmp_path)
handler.query_server_last_sync = lambda client_id=None: None
handler.needs_recovery = lambda server_info: (False, False)
session = db_manager.get_session()
try:
session.add(PersistentRedistributionAdjustmentModel(
date=date(1970, 1, 1),
accumulated_shortfall=-33.0,
total_payin=200.0,
total_redistributed=233.0,
cap_percentage=70.0,
))
bet = BetModel(uuid='bet-collect-1', fixture_id='fixture-1', paid=True, paid_out=False, bet_datetime=datetime.utcnow())
session.add(bet)
session.flush()
match = MatchModel(
match_number=1,
fighter1_township='A',
fighter2_township='B',
venue_kampala_township='Kampala',
filename='fixture.txt',
file_sha1sum='fixture-sha1',
fixture_id='fixture-1',
active_status=True,
status='done',
start_time=datetime.utcnow(),
accumulated_shortfall=-20.0,
cap_percent=70.0,
)
session.add(match)
session.flush()
session.add(BetDetailModel(
bet_id='bet-collect-1',
match_id=match.id,
match_number=1,
outcome='WIN1',
amount=25.0,
win_amount=75.0,
result='win',
))
session.add(ExtractionStatsModel(
match_id=match.id,
fixture_id='fixture-1',
match_datetime=match.start_time,
total_bets=1,
total_amount_collected=25.0,
total_redistributed=75.0,
actual_result='WIN1',
result_breakdown={},
under_bets=0,
under_amount=0.0,
over_bets=0,
over_amount=0.0,
extraction_result='WIN1',
cap_applied=False,
cap_percentage=None,
))
session.commit()
report_data = handler.collect_report_data('today')
assert report_data['summary']['total_payin'] == 25.0
assert report_data['summary']['total_payout'] == 75.0
assert report_data['summary']['global_carryover_balance'] == -33.0
assert report_data['cap_compensation_balance'] == -33.0
assert report_data['global_carryover_balance'] == -33.0
finally:
session.close()
db_manager.close()
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