[FIX] Google Calendar - Split the last underscore because Google uses sometimes ...
authorJeremy Kersten <jke@odoo.com>
Fri, 13 Jun 2014 15:57:01 +0000 (17:57 +0200)
committerJeremy Kersten <jke@odoo.com>
Fri, 13 Jun 2014 15:57:01 +0000 (17:57 +0200)
addons/google_calendar/google_calendar.py

index f36062b..b8b6014 100644 (file)
@@ -530,7 +530,7 @@ class google_calendar(osv.AbstractModel):
         for att in att_obj.browse(cr, uid, my_att_ids, context=context):
             event = att.event_id
 
-            base_event_id = att.google_internal_event_id.split('_')[0]
+            base_event_id = att.google_internal_event_id.rsplit('_', 1)[0]
 
             if base_event_id not in event_to_synchronize:
                 event_to_synchronize[base_event_id] = {}
@@ -552,7 +552,7 @@ class google_calendar(osv.AbstractModel):
 
         for event in all_event_from_google.values():
             event_id = event.get('id')
-            base_event_id = event_id.split('_')[0]
+            base_event_id = event_id.rsplit('_', 1)[0]
 
             if base_event_id not in event_to_synchronize:
                 event_to_synchronize[base_event_id] = {}
@@ -615,7 +615,7 @@ class google_calendar(osv.AbstractModel):
                     if actSrc == 'OE':
                         self.delete_an_event(cr, uid, current_event[0], context=context)
                     elif actSrc == 'GG':
-                            new_google_event_id = event.GG.event['id'].split('_')[1]
+                            new_google_event_id = event.GG.event['id'].rsplit('_', 1)[1]
                             if 'T' in new_google_event_id:
                                 new_google_event_id = new_google_event_id.replace('T', '')[:-1]
                             else:
@@ -623,7 +623,11 @@ class google_calendar(osv.AbstractModel):
 
                                 if event.GG.status:
                                     parent_event = {}
-                                    parent_event['id'] = "%s-%s" % (event_to_synchronize[base_event][0][1].OE.event_id, new_google_event_id)
+                                    if event_to_synchronize[base_event][0][1].OE.event_id:
+                                        parent_event['id'] = "%s-%s" % (event_to_synchronize[base_event][0][1].OE.event_id, new_google_event_id)
+                                    else:
+                                        main_ev = att_obj.search_read(cr, uid, [('google_internal_event_id', '=', event.GG.event['id'].rsplit('_', 1)[0])], fields=['event_id'], context=context)
+                                        parent_event['id'] = "%s-%s" % (main_ev[0].get('event_id')[0], new_google_event_id)
                                     res = self.update_from_google(cr, uid, parent_event, event.GG.event, "copy", context)
                                 else:
                                     if event_to_synchronize[base_event][0][1].OE.event_id: