From 4e4068446c02bd25d5865a24b4b89895316392ab Mon Sep 17 00:00:00 2001 From: Marc Durepos Date: Fri, 5 Jul 2024 09:04:51 -0400 Subject: [PATCH] caldav_sync: fix a bug where deleting an event fails to remove it from iCloud calendars. --- caldav_sync/__manifest__.py | 7 +----- caldav_sync/data/caldav_sync_data.xml | 26 +++++++++++------------ caldav_sync/models/calendar_event.py | 16 ++++++-------- caldav_sync/requirements.txt | 3 +++ caldav_sync/static/description/index.html | 8 ++++++- caldav_sync/views/res_users_views.xml | 24 ++++++++++----------- 6 files changed, 42 insertions(+), 42 deletions(-) create mode 100644 caldav_sync/requirements.txt diff --git a/caldav_sync/__manifest__.py b/caldav_sync/__manifest__.py index e7242cf..8528768 100644 --- a/caldav_sync/__manifest__.py +++ b/caldav_sync/__manifest__.py @@ -8,15 +8,10 @@ { "name": "CalDAV Synchronization", - "version": "17.0.0.5.5", + "version": "17.0.0.5.6", "license": "LGPL-3", "category": "Productivity", "summary": "Synchronize Odoo Calendar Events with CalDAV Servers", - "description": """ - This module allows Odoo to synchronize calendar events with CalDAV servers. - Users can synchronize their Odoo calendar with external applications like - Apple Calendar or Thunderbird using CalDAV protocol. - """, "author": "Bemade Inc.", "website": "https://www.bemade.org", "depends": ["base", "calendar"], diff --git a/caldav_sync/data/caldav_sync_data.xml b/caldav_sync/data/caldav_sync_data.xml index 4447d6b..a97fad2 100644 --- a/caldav_sync/data/caldav_sync_data.xml +++ b/caldav_sync/data/caldav_sync_data.xml @@ -1,15 +1,13 @@ - - - - CalDAV Sync - - code - model.poll_caldav_server() - 1 - minutes - -1 - - - - + + + CalDAV Sync + + code + model.poll_caldav_server() + 1 + minutes + -1 + + + diff --git a/caldav_sync/models/calendar_event.py b/caldav_sync/models/calendar_event.py index 1dec89d..a117cf0 100644 --- a/caldav_sync/models/calendar_event.py +++ b/caldav_sync/models/calendar_event.py @@ -3,11 +3,12 @@ from odoo import models, api, fields from odoo.exceptions import UserError import caldav import logging -from datetime import datetime, timezone +from datetime import datetime from icalendar import Calendar, Event, vCalAddress, vText from bs4 import BeautifulSoup import re from pytz import timezone, utc +from caldav.elements.cdav import CompFilter _logger = logging.getLogger(__name__) @@ -132,8 +133,7 @@ class CalendarEvent(models.Model): if event.caldav_uid: try: _logger.debug(f"Removing CalDAV event {event.caldav_uid}") - caldav_event = calendar.object_by_uid(event.caldav_uid) - caldav_event.delete() + event._get_icalendar().delete() except caldav.error.NotFoundError: _logger.warning( f"CalDAV event {event.caldav_uid} not found on server." @@ -217,9 +217,9 @@ class CalendarEvent(models.Model): msg = f"""Failed to connect to the calendar, but successfully connected to the server at {client.url}. You may need to select another calendar URL from those below. - + Available calendars: - + """ for calendar in principal.calendars(): msg += f"{calendar.name}: {calendar.url}\n" @@ -382,7 +382,7 @@ class CalendarEvent(models.Model): values.update(recurrency_vals) if not existing_instance: _logger.info(f"Creating with vals: {values}") - self.with_context({"caldav_no_sync": True}).create(values) + self.with_context(caldav_no_sync=True).create(values) else: _logger.info(f"Updating with vals: {values}") changed_vals = {} @@ -414,9 +414,7 @@ class CalendarEvent(models.Model): } ) existing_instance.with_context( - { - "caldav_no_sync": True, - } + caldav_no_sync=True, ).write(changed_vals) @staticmethod diff --git a/caldav_sync/requirements.txt b/caldav_sync/requirements.txt new file mode 100644 index 0000000..895ba39 --- /dev/null +++ b/caldav_sync/requirements.txt @@ -0,0 +1,3 @@ +caldav==1.3.9 +icalendar==5.0.13 +bs4==0.0.2 diff --git a/caldav_sync/static/description/index.html b/caldav_sync/static/description/index.html index 3331b10..a09ded5 100644 --- a/caldav_sync/static/description/index.html +++ b/caldav_sync/static/description/index.html @@ -42,7 +42,13 @@
  1. Install the module in Odoo.
  2. Go to the User settings in Odoo.
  3. -
  4. Enter the CalDAV calendar URL, username, and password on the user settings.
  5. +
  6. + Enter the CalDAV calendar URL, username, and password on the user settings. + In some cases, the calendar URL to use is not evident. For Apple iCloud + calendars, for example, we recommend starting with the base server url + at https://caldav.icloud.com/ and then selecting a specific calendar url + from the error given in the server logs. +

Note: Some calendar service providers such as Apple iCloud require app-specific passwords to be set so that diff --git a/caldav_sync/views/res_users_views.xml b/caldav_sync/views/res_users_views.xml index 46c1f73..f082fd8 100644 --- a/caldav_sync/views/res_users_views.xml +++ b/caldav_sync/views/res_users_views.xml @@ -1,32 +1,32 @@ - - res.users.form + + res.users.form.inherit res.users - + - - - + + + - - res.users.form + + res.users.form.simple.modif.inherit res.users - + - - - + + +