diff --git a/src/clear_bookings.py b/src/clear_bookings.py index 9019f36..6422838 100644 --- a/src/clear_bookings.py +++ b/src/clear_bookings.py @@ -158,6 +158,14 @@ class DavEvent: self.is_deleted = True self.obj.delete() + def cancel(self): + """ + Cancel the event. + :return: + """ + self.obj.icalendar_component["status"] = "CANCELLED" + self.obj.save(no_create=True) + def serialize(self) -> dict[str, str | datetime | timedelta]: """ Serialize the event to a dictionary. @@ -314,8 +322,7 @@ def clear(target_calendars: list, is_test: bool=False) -> dict: # we need to cancel it now elif not event.is_cancelled: if not is_test: - event.obj.icalendar_component["status"] = "CANCELLED" - event.obj.save() + event.cancel() is_cancelled = True result["cancellation_type"] = "cancelled" results["cancelled_overlapping_recurring_events"].append(result)