[IMP] google_calendar - synchronize OE alarm with google reminders
This commit is contained in:
parent
5b283419d3
commit
aed865aa93
|
@ -212,13 +212,20 @@ class google_calendar(osv.AbstractModel):
|
||||||
type = 'dateTime'
|
type = 'dateTime'
|
||||||
vstype = 'date'
|
vstype = 'date'
|
||||||
attendee_list = []
|
attendee_list = []
|
||||||
|
|
||||||
for attendee in event.attendee_ids:
|
for attendee in event.attendee_ids:
|
||||||
attendee_list.append({
|
attendee_list.append({
|
||||||
'email': attendee.email or 'NoEmail@mail.com',
|
'email': attendee.email or 'NoEmail@mail.com',
|
||||||
'displayName': attendee.partner_id.name,
|
'displayName': attendee.partner_id.name,
|
||||||
'responseStatus': attendee.state or 'needsAction',
|
'responseStatus': attendee.state or 'needsAction',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
reminders = []
|
||||||
|
for alarm in event.alarm_ids:
|
||||||
|
reminders.append({
|
||||||
|
"method": "email" if alarm.type == "email" else "popup",
|
||||||
|
"minutes": alarm.duration_minutes
|
||||||
|
})
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"summary": event.name or '',
|
"summary": event.name or '',
|
||||||
"description": event.description or '',
|
"description": event.description or '',
|
||||||
|
@ -233,6 +240,7 @@ class google_calendar(osv.AbstractModel):
|
||||||
'timeZone': 'UTC'
|
'timeZone': 'UTC'
|
||||||
},
|
},
|
||||||
"attendees": attendee_list,
|
"attendees": attendee_list,
|
||||||
|
"reminders": {"overrides": reminders},
|
||||||
"location": event.location or '',
|
"location": event.location or '',
|
||||||
"visibility": event['class'] or 'public',
|
"visibility": event['class'] or 'public',
|
||||||
}
|
}
|
||||||
|
@ -244,7 +252,6 @@ class google_calendar(osv.AbstractModel):
|
||||||
|
|
||||||
if not self.get_need_synchro_attendee(cr, uid, context=context):
|
if not self.get_need_synchro_attendee(cr, uid, context=context):
|
||||||
data.pop("attendees")
|
data.pop("attendees")
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def create_an_event(self, cr, uid, event, context=None):
|
def create_an_event(self, cr, uid, event, context=None):
|
||||||
|
@ -400,14 +407,16 @@ class google_calendar(osv.AbstractModel):
|
||||||
calendar_event = self.pool['calendar.event']
|
calendar_event = self.pool['calendar.event']
|
||||||
res_partner_obj = self.pool['res.partner']
|
res_partner_obj = self.pool['res.partner']
|
||||||
calendar_attendee_obj = self.pool['calendar.attendee']
|
calendar_attendee_obj = self.pool['calendar.attendee']
|
||||||
|
calendar_alarm_obj = self.pool['calendar.alarm']
|
||||||
user_obj = self.pool['res.users']
|
user_obj = self.pool['res.users']
|
||||||
myPartnerID = user_obj.browse(cr, uid, uid, context).partner_id.id
|
myPartnerID = user_obj.browse(cr, uid, uid, context).partner_id.id
|
||||||
attendee_record = []
|
attendee_record = []
|
||||||
|
alarm_record = []
|
||||||
partner_record = [(4, myPartnerID)]
|
partner_record = [(4, myPartnerID)]
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
if single_event_dict.get('attendees', False):
|
if self.get_need_synchro_attendee(cr, uid, context=context):
|
||||||
for google_attendee in single_event_dict['attendees']:
|
for google_attendee in single_event_dict.get('attendees', []):
|
||||||
if type == "write":
|
if type == "write":
|
||||||
for oe_attendee in event['attendee_ids']:
|
for oe_attendee in event['attendee_ids']:
|
||||||
if oe_attendee.email == google_attendee['email']:
|
if oe_attendee.email == google_attendee['email']:
|
||||||
|
@ -415,22 +424,41 @@ class google_calendar(osv.AbstractModel):
|
||||||
google_attendee['found'] = True
|
google_attendee['found'] = True
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if google_attendee.get('found', False):
|
if google_attendee.get('found'):
|
||||||
continue
|
continue
|
||||||
if self.get_need_synchro_attendee(cr, uid, context=context):
|
|
||||||
attendee_id = res_partner_obj.search(cr, uid, [('email', '=', google_attendee['email'])], context=context)
|
attendee_id = res_partner_obj.search(cr, uid, [('email', '=', google_attendee['email'])], context=context)
|
||||||
if not attendee_id:
|
if not attendee_id:
|
||||||
data = {
|
data = {
|
||||||
'email': google_attendee['email'],
|
'email': google_attendee['email'],
|
||||||
'customer': False,
|
'customer': False,
|
||||||
'name': google_attendee.get("displayName", False) or google_attendee['email']
|
'name': google_attendee.get("displayName", False) or google_attendee['email']
|
||||||
}
|
}
|
||||||
attendee_id = [res_partner_obj.create(cr, uid, data, context=context)]
|
attendee_id = [res_partner_obj.create(cr, uid, data, context=context)]
|
||||||
attendee = res_partner_obj.read(cr, uid, attendee_id[0], ['email'], context=context)
|
attendee = res_partner_obj.read(cr, uid, attendee_id[0], ['email'], context=context)
|
||||||
partner_record.append((4, attendee.get('id')))
|
partner_record.append((4, attendee.get('id')))
|
||||||
attendee['partner_id'] = attendee.pop('id')
|
attendee['partner_id'] = attendee.pop('id')
|
||||||
attendee['state'] = google_attendee['responseStatus']
|
attendee['state'] = google_attendee['responseStatus']
|
||||||
attendee_record.append((0, 0, attendee))
|
attendee_record.append((0, 0, attendee))
|
||||||
|
for google_alarm in single_event_dict.get('reminders', {}).get('overrides', []):
|
||||||
|
alarm_id = calendar_alarm_obj.search(
|
||||||
|
cr,
|
||||||
|
uid,
|
||||||
|
[
|
||||||
|
('type', '=', google_alarm['method'] if google_alarm['method'] == 'email' else 'notification'),
|
||||||
|
('duration_minutes', '=', google_alarm['minutes'])
|
||||||
|
],
|
||||||
|
context=context
|
||||||
|
)
|
||||||
|
if not alarm_id:
|
||||||
|
data = {
|
||||||
|
'type': google_alarm['method'] if google_alarm['method'] == 'email' else 'notification',
|
||||||
|
'duration': google_alarm['minutes'],
|
||||||
|
'interval': 'minutes',
|
||||||
|
'name': "%s minutes - %s" % (google_alarm['minutes'], google_alarm['method'])
|
||||||
|
}
|
||||||
|
alarm_id = [calendar_alarm_obj.create(cr, uid, data, context=context)]
|
||||||
|
alarm_record.append(alarm_id[0])
|
||||||
|
|
||||||
UTC = pytz.timezone('UTC')
|
UTC = pytz.timezone('UTC')
|
||||||
if single_event_dict.get('start') and single_event_dict.get('end'): # If not cancelled
|
if single_event_dict.get('start') and single_event_dict.get('end'): # If not cancelled
|
||||||
|
@ -458,6 +486,7 @@ class google_calendar(osv.AbstractModel):
|
||||||
result.update({
|
result.update({
|
||||||
'attendee_ids': attendee_record,
|
'attendee_ids': attendee_record,
|
||||||
'partner_ids': list(set(partner_record)),
|
'partner_ids': list(set(partner_record)),
|
||||||
|
'alarm_ids': [(6, 0, alarm_record)],
|
||||||
|
|
||||||
'name': single_event_dict.get('summary', 'Event'),
|
'name': single_event_dict.get('summary', 'Event'),
|
||||||
'description': single_event_dict.get('description', False),
|
'description': single_event_dict.get('description', False),
|
||||||
|
@ -943,7 +972,7 @@ class calendar_event(osv.Model):
|
||||||
_inherit = "calendar.event"
|
_inherit = "calendar.event"
|
||||||
|
|
||||||
def get_fields_need_update_google(self, cr, uid, context=None):
|
def get_fields_need_update_google(self, cr, uid, context=None):
|
||||||
return ['name', 'description', 'allday', 'date', 'date_end', 'stop', 'attendee_ids', 'location', 'class', 'active']
|
return ['name', 'description', 'allday', 'date', 'date_end', 'stop', 'attendee_ids', 'alarm_ids', 'location', 'class', 'active']
|
||||||
|
|
||||||
def write(self, cr, uid, ids, vals, context=None):
|
def write(self, cr, uid, ids, vals, context=None):
|
||||||
if context is None:
|
if context is None:
|
||||||
|
|
Loading…
Reference in New Issue