[ADD][WIP]Radicale Odoo Storage : three calendar for authenticated user (own, in, all)
This commit is contained in:
parent
671962ca5c
commit
cab13778ab
@ -23,9 +23,11 @@
|
||||
# 3. OK : Implement unique events (.ics) and timezone
|
||||
# 4. OK : Implement notifications for events
|
||||
# 5. OK : Implement recurrent events
|
||||
# 6. Offer two (or more) calendar : own events, events where I'm attended and all readable events
|
||||
# 7. Begin write (two way) for contacts
|
||||
# 8. Begin write (two way) for calendar
|
||||
# 6. OK : Offer two (or more) calendar : own events, events where I'm attended
|
||||
# and all readable events
|
||||
# 7. Offer one calendar per user (via login/email)
|
||||
# 8. Begin write (two way) for contacts
|
||||
# 9. Begin write (two way) for calendar
|
||||
|
||||
|
||||
from contextlib import contextmanager
|
||||
@ -64,13 +66,22 @@ class Collection(BaseCollection):
|
||||
self.props.update({'tag': 'VADDRESSBOOK',
|
||||
'D:displayname': 'Odoo contacts',
|
||||
'CR:addressbook-description': 'Contacts form your Odoo account'})
|
||||
elif 'odoo-calendar' in attributes:
|
||||
elif ('odoo-calendar-own' in attributes or
|
||||
'odoo-calendar-in' in attributes or 'odoo-calendar-all' in attributes):
|
||||
self.tag = 'VCALENDAR'
|
||||
self.odoo_model = 'calendar.event'
|
||||
self.content_suffix = '.ics'
|
||||
self.props.update({'tag': 'VCALENDAR',
|
||||
'D:displayname': 'Odoo calendar',
|
||||
'C:calendar-description': 'Events form your Odoo calendar'})
|
||||
self.props.update({'tag': 'VCALENDAR'})
|
||||
if 'odoo-calendar-own' in attributes:
|
||||
self.props.update({'D:displayname': 'Odoo calendar : own events',
|
||||
'C:calendar-description': 'Own events, from your Odoo calendar'})
|
||||
elif 'odoo-calendar-in' in attributes:
|
||||
self.props.update({'D:displayname': 'Odoo calendar : events I\'m in',
|
||||
'C:calendar-description': 'Events you are ' \
|
||||
'attended from your Odoo calendar'})
|
||||
else:
|
||||
self.props.update({'D:displayname': 'Odoo calendar : all events',
|
||||
'C:calendar-description': 'All events from your Odoo calendar'})
|
||||
|
||||
self.path = path.strip('/')
|
||||
self.owner = attributes[0]
|
||||
@ -100,9 +111,13 @@ class Collection(BaseCollection):
|
||||
yield cls(path)
|
||||
if len(attributes) == 1: # Got all if root is needed
|
||||
contact_path = '%sodoo-contact' % path
|
||||
calendar_path = '%sodoo-calendar' % path
|
||||
calendar_own_path = '%sodoo-calendar-own' % path
|
||||
calendar_in_path = '%sodoo-calendar-in' % path
|
||||
calendar_all_path = '%sodoo-calendar-all' % path
|
||||
yield cls(contact_path)
|
||||
yield cls(calendar_path)
|
||||
yield cls(calendar_own_path)
|
||||
yield cls(calendar_in_path)
|
||||
yield cls(calendar_all_path)
|
||||
elif len(attributes) == 2: # Then we need children
|
||||
collection = cls(path)
|
||||
for item in collection.list():
|
||||
@ -128,11 +143,19 @@ class Collection(BaseCollection):
|
||||
return ['res.partner:%s' % pid for pid in partner_ids]
|
||||
|
||||
@classmethod
|
||||
def get_events_from_odoo(cls, login):
|
||||
def get_events_from_odoo(cls, login, path):
|
||||
""" Gets all events available from one Odoo login """
|
||||
cls.logger.info('Get events for Odoo user %s' % login)
|
||||
cls.odoo.env.context.update({'virtual_id': False}) # Only real events
|
||||
event_ids = cls.odoo.env['calendar.event'].search([])
|
||||
if path.endswith('odoo-calendar-own'):
|
||||
domain = [('user_id', '=', cls.odoo.env.uid)]
|
||||
elif path.endswith('odoo-calendar-in'):
|
||||
pid = cls.odoo.execute('res.users', 'read', [cls.odoo.env.uid],
|
||||
['partner_id'])[0]['partner_id'][0]
|
||||
domain = [('partner_ids', '=', pid)]
|
||||
else:
|
||||
domain = []
|
||||
event_ids = cls.odoo.env['calendar.event'].search(domain)
|
||||
# WARNING: Odoo does not remove from database deleted recurrent events...
|
||||
# Should be fixed on Odoo side and will be fixed via 2way here too
|
||||
return ['calendar.event:%s' % eid for eid in event_ids]
|
||||
@ -153,7 +176,7 @@ class Collection(BaseCollection):
|
||||
for oid in self.get_contacts_from_odoo(self.owner):
|
||||
yield oid + self.content_suffix
|
||||
elif self.tag == 'VCALENDAR':
|
||||
for oid in self.get_events_from_odoo(self.owner):
|
||||
for oid in self.get_events_from_odoo(self.owner, self.path):
|
||||
yield oid + self.content_suffix
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
Loading…
Reference in New Issue
Block a user