From 4ad60aeba09cded0ad8ad80e0039a1d9adf61f89 Mon Sep 17 00:00:00 2001 From: vishwajeet-13 Date: Sat, 23 May 2026 17:55:46 +0530 Subject: [PATCH] fix: prevent duplicate attendance records --- .../doctype/zoom_webinar/zoom_webinar.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/zoom_integration/zoom_integration/doctype/zoom_webinar/zoom_webinar.py b/zoom_integration/zoom_integration/doctype/zoom_webinar/zoom_webinar.py index 059be3a..893f657 100644 --- a/zoom_integration/zoom_integration/doctype/zoom_webinar/zoom_webinar.py +++ b/zoom_integration/zoom_integration/doctype/zoom_webinar/zoom_webinar.py @@ -276,9 +276,19 @@ def sync_attendance(self): batch = details[i : i + batch_size] for attendance in batch: + user_email = attendance.get("user_email") + if not user_email: + continue + + if frappe.db.exists( + "Zoom Webinar Attendance Record", + {"webinar": self.name, "user_email": user_email}, + ): + continue + registration = frappe.db.get_value( "Zoom Webinar Registration", - {"email": attendance.get("user_email", "N/A")}, + {"email": user_email}, "name", ) @@ -288,18 +298,18 @@ def sync_attendance(self): "doctype": "Zoom Webinar Attendance Record", "registration": registration, "webinar": self.name, - "user_email": attendance.get("user_email"), + "user_email": user_email, "full_name": attendance.get("name"), "total_duration": attendance.get("total_duration"), "registrant_id": attendance.get("registrant_id"), "docstatus": 1, } ) - doc.insert(ignore_permissions=True, ignore_if_duplicate=True) + doc.insert(ignore_permissions=True) processed_count += 1 except Exception as e: frappe.log_error( - message=f"Failed to create attendance record for {attendance.get('user_email')}: {e!s}", + message=f"Failed to create attendance record for {user_email}: {e!s}", title="Attendance Sync Error", ) continue @@ -424,9 +434,6 @@ def sync_registrations_from_zoom(self): # Commit batch to avoid long transactions frappe.db.commit() - self.attendance_synced = 1 - self.save() - frappe.publish_progress( percent=100, title="Creating Registrant Records",