attempt fix for recurring email blasts to attendees on the hour

This commit is contained in:
Marc Durepos 2024-05-29 10:02:41 -04:00
parent 2933702012
commit 9733d63bb7

View file

@ -6,7 +6,6 @@ from datetime import datetime, timezone
from icalendar import Calendar, Event, vCalAddress, vText, vWeekday from icalendar import Calendar, Event, vCalAddress, vText, vWeekday
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from datetime import timedelta from datetime import timedelta
import dateutil
import re import re
from pytz import timezone, utc from pytz import timezone, utc
@ -320,7 +319,6 @@ class CalendarEvent(models.Model):
end = component.decoded('dtend') end = component.decoded('dtend')
if isinstance(end, datetime): if isinstance(end, datetime):
end = end.astimezone(utc).replace(tzinfo=None) end = end.astimezone(utc).replace(tzinfo=None)
values = { values = {
'name': str(component.get('summary')), 'name': str(component.get('summary')),
'start': start, 'start': start,
@ -339,12 +337,27 @@ class CalendarEvent(models.Model):
self.with_context({'caldav_no_sync': True}).create(values) self.with_context({'caldav_no_sync': True}).create(values)
else: else:
_logger.info(f"Updating with vals: {values}") _logger.info(f"Updating with vals: {values}")
if recurrency_vals and recurrency_vals.get('recurrency'): changed_vals = {}
# Don't update partner_ids if no change
if attendee_ids - existing_instance.partner_ids:
changed_vals.update({
'partner_ids',values.pop('partner_ids'),
})
# Don't write values that haven't changed
for key, val in values.items():
if getattr(existing_instance, key) != val:
changed_vals.update({key: values.pop(key)})
if (recurrency_vals and recurrency_vals.get('recurrency')
and (not existing_instance.recurrency or not
existing_instance.follow_recurrence)):
existing_instance.write({ existing_instance.write({
'recurrency': True, 'recurrency': True,
'follow_recurrence': True, 'follow_recurrence': True,
}) })
existing_instance.with_context({'caldav_no_sync': True}).write(values) existing_instance.with_context({
'caldav_no_sync': True,
}).write(changed_vals)
@staticmethod @staticmethod
def _extract_component_text(component, subcomponent_name): def _extract_component_text(component, subcomponent_name):