[FIX] calendar: don't crash on missing optional dependency

For historical reasons, `vobject`* Python library is not mandatory in
Odoo.

Since refactoring 6af6148a24,
get_ics_file() returns now a dictionary whose keys are calendar.event
ids and values are the corresponding ics file.
If `vobject` is not available, it returns an empty dictionary that
could cause calendar.py to crash because it always expects to find the
event's key.

Before this refactoring, this method was called and architectured in a
different manner, so no crash was happening.

This commit prevents the crash if `vobject` is not installed and logs a
warning.

*vobject allows to generate iCalendar files
This commit is contained in:
Richard Mathot
2016-09-28 13:43:20 +02:00
committed by Jérome Maes
parent 4dd31f645e
commit 2bb37b5d1e
+2 -1
View File
@@ -160,7 +160,7 @@ class Attendee(models.Model):
mails_to_send = self.env['mail.mail']
for attendee in self:
if attendee.email or attendee.partner_id.email:
ics_file = ics_files[attendee.event_id.id]
ics_file = ics_files.get(attendee.event_id.id)
mail_id = invitation_template.send_mail(attendee.id)
vals = {}
@@ -850,6 +850,7 @@ class Meeting(models.Model):
# FIXME: why isn't this in CalDAV?
import vobject
except ImportError:
_logger.warning("The `vobject` Python module is not installed, so iCal file generation is unavailable. Use 'pip install vobject' to install it")
return result
for meeting in self: