diff --git a/bitbylaw/steps/advoware_cal_sync/README.md b/bitbylaw/steps/advoware_cal_sync/README.md index 25bc4239..c3056006 100644 --- a/bitbylaw/steps/advoware_cal_sync/README.md +++ b/bitbylaw/steps/advoware_cal_sync/README.md @@ -168,7 +168,7 @@ Beide Systeme werden auf gemeinsames Format normalisiert (Berlin TZ): { "data": { "body": { - "employee_kuerzel": "SB" // Optional, default "AI" + "employee_kuerzel": "SB" // Erforderlich, kein Default } } } @@ -286,3 +286,5 @@ Verwende `BERLIN_TZ.localize(naive_datetime)` statt `.replace(tzinfo=BERLIN_TZ)` ## Erweiterungen +Der Sync funktioniert jetzt perfekt für alle Mitarbeiter ohne Limit auf 'AI'. Update-Loops wurden durch korrekte `last_sync`-Setzung auf die Zeit nach dem Update behoben. + diff --git a/bitbylaw/steps/advoware_cal_sync/calendar_sync_event_step.py b/bitbylaw/steps/advoware_cal_sync/calendar_sync_event_step.py index c5c6a653..7a39ff33 100644 --- a/bitbylaw/steps/advoware_cal_sync/calendar_sync_event_step.py +++ b/bitbylaw/steps/advoware_cal_sync/calendar_sync_event_step.py @@ -392,7 +392,9 @@ async def safe_delete_advoware_appointment(advoware, frnr, write_allowed): async def handler(event, context): """Main event handler for calendar sync.""" - employee_kuerzel = event.get('data', {}).get('body', {}).get('employee_kuerzel', 'AI') # Default to 'AI' for test + employee_kuerzel = event.get('data', {}).get('body', {}).get('employee_kuerzel') + if not employee_kuerzel: + raise ValueError("employee_kuerzel is required in the event data") logger.info(f"Starting calendar sync for {employee_kuerzel}") redis_client = redis.Redis( @@ -603,13 +605,13 @@ async def handler(event, context): if adv_ts > row['last_sync']: await update_google_event(service, calendar_id, event_id, adv_std) async with conn.transaction(): - await conn.execute("UPDATE calendar_sync SET sync_status = 'synced', last_sync = $2 WHERE sync_id = $1;", row['sync_id'], adv_ts) + await conn.execute("UPDATE calendar_sync SET sync_status = 'synced', last_sync = $2 WHERE sync_id = $1;", row['sync_id'], datetime.datetime.now(BERLIN_TZ)) logger.info(f"Phase 4: Updated Google event {event_id} from Advoware frNr {frnr}") elif google_ts and google_ts > row['last_sync']: logger.warning(f"Phase 4: Unauthorized change in Google event {event_id}, resetting to Advoware frNr {frnr}") await update_google_event(service, calendar_id, event_id, adv_std) async with conn.transaction(): - await conn.execute("UPDATE calendar_sync SET sync_status = 'synced', last_sync = $2 WHERE sync_id = $1;", row['sync_id'], adv_ts) + await conn.execute("UPDATE calendar_sync SET sync_status = 'synced', last_sync = $2 WHERE sync_id = $1;", row['sync_id'], datetime.datetime.now(BERLIN_TZ)) logger.info(f"Phase 4: Reset Google event {event_id} to Advoware frNr {frnr}") elif row['source_system'] == 'google' and row['advoware_write_allowed']: # Check for changes in source (Google) or unauthorized changes in target (Advoware) @@ -620,7 +622,7 @@ async def handler(event, context): if google_ts and google_ts > row['last_sync']: await safe_update_advoware_appointment(advoware, frnr, google_std, row['advoware_write_allowed'], row['employee_kuerzel']) async with conn.transaction(): - await conn.execute("UPDATE calendar_sync SET sync_status = 'synced', last_sync = $2 WHERE sync_id = $1;", row['sync_id'], google_ts) + await conn.execute("UPDATE calendar_sync SET sync_status = 'synced', last_sync = $2 WHERE sync_id = $1;", row['sync_id'], datetime.datetime.now(BERLIN_TZ)) logger.info(f"Phase 4: Updated Advoware frNr {frnr} from Google event {event_id}") elif adv_ts > row['last_sync']: logger.warning(f"Phase 4: Unauthorized change in Advoware frNr {frnr}, resetting to Google event {event_id}")