diff --git a/addons/caldav/common.py b/addons/caldav/common.py index 77187c91419..2119584a399 100644 --- a/addons/caldav/common.py +++ b/addons/caldav/common.py @@ -51,19 +51,26 @@ def real_id2caldav_id(real_id, recurrent_date): return '%d-%s'%(real_id, recurrent_date) return real_id -def uid2openobjectid(cr, uidval, oomodel): +def uid2openobjectid(cr, uidval, oomodel, rdate): __rege = re.compile(r'OpenObject-([\w|\.]+)_([0-9]+)@(\w+)$') wematch = __rege.match(uidval.encode('utf8')) if not wematch: - return False + return (False, None) else: model, id, dbname = wematch.groups() if (not model == oomodel) or (not dbname == cr.dbname): - return False - cr.execute('select distinct(id) from %s' % model.replace('.', '_')) + return (False, None) + qry = 'select distinct(id) from %s' % model.replace('.', '_') + if rdate: + qry += " where recurrent_id='%s'" % (rdate) + cr.execute(qry) + r_id = cr.fetchone() + if r_id: + return (id, r_id[0]) + cr.execute(qry) ids = map(lambda x: str(x[0]), cr.fetchall()) if id in ids: - return id + return (id, None) return False def openobjectid2uid(cr, uidval, oomodel): diff --git a/addons/crm/crm_meeting.py b/addons/crm/crm_meeting.py index 27d744c38d2..d73823bd710 100644 --- a/addons/crm/crm_meeting.py +++ b/addons/crm/crm_meeting.py @@ -194,13 +194,18 @@ rule or repeating pattern for anexception to a recurrence set"), vals = event_obj.import_ical(cr, uid, file_content) ids = [] for val in vals: - is_exists = common.uid2openobjectid(cr, val['id'], self._name) + exists, r_id = common.uid2openobjectid(cr, val['id'], self._name, \ + val.get('recurrent_id')) if val.has_key('create_date'): val.pop('create_date') val['caldav_url'] = context.get('url') or '' val.pop('id') - if is_exists: - self.write(cr, uid, [is_exists], val) - ids.append(is_exists) + if exists and r_id: + val.update({'recurrent_uid': exists}) + self.write(cr, uid, [r_id], val) + ids.append(r_id) + elif exists: + self.write(cr, uid, [exists], val) + ids.append(exists) else: case_id = self.create(cr, uid, val) ids.append(case_id)