From dcd7fd9a569c21edf396845d805d040978f70feb Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Wed, 3 Mar 2010 18:29:53 +0530 Subject: [PATCH] [IMP]: caldav, base_calendar: Improvement for exdate export and recurrent date import bzr revid: rpa@openerp.co.in-20100303125953-utr46gibwcsbu7ie --- addons/base_calendar/base_calendar.py | 6 +++-- addons/caldav/caldav.py | 36 +++++++++++++++++---------- addons/crm_caldav/crm_caldav.py | 25 +------------------ 3 files changed, 28 insertions(+), 39 deletions(-) diff --git a/addons/base_calendar/base_calendar.py b/addons/base_calendar/base_calendar.py index 584762828f1..82ceb2aab70 100644 --- a/addons/base_calendar/base_calendar.py +++ b/addons/base_calendar/base_calendar.py @@ -38,7 +38,7 @@ months = { def get_recurrent_dates(rrulestring, exdate, startdate=None): def todate(date): - val = parser.parse(''.join((re.compile('\d')).findall(date)) + 'Z') + val = parser.parse(''.join((re.compile('\d')).findall(date))) return val if not startdate: startdate = datetime.now() @@ -778,13 +778,15 @@ rule or repeating pattern for anexception to a recurrence set"), def modify_this(self, cr, uid, ids, defaults, context=None, *args): datas = self.read(cr, uid, ids[0], context=context) - date = datas.get('date') defaults.update({ 'recurrent_uid': base_calendar_id2real_id(datas['id']), 'recurrent_id': defaults.get('date'), 'rrule_type': 'none', 'rrule': '' }) + exdate = datas['exdate'] and datas['exdate'].split(',') or [] + exdate.append(defaults.get('date')) + self.write(cr, uid, ids, {'exdate': ','.join(exdate)}, context=context) new_id = self.copy(cr, uid, ids[0], default=defaults, context=context) return new_id diff --git a/addons/caldav/caldav.py b/addons/caldav/caldav.py index 6c416903959..48f845176d4 100644 --- a/addons/caldav/caldav.py +++ b/addons/caldav/caldav.py @@ -248,15 +248,15 @@ class CalDAV(object): data[map_field], ical, context=context) elif data[map_field]: if map_type in ("char", "text"): - vevent.add(field).value = tools.ustr(data[map_field]) - elif map_type in ('datetime', 'date') and data[map_field]: if field in ('exdate'): - vevent.add(field).value = [parser.parse(data[map_field])] + vevent.add(field).value = map(parser.parse, (data[map_field]).split(',')) else: - dtfield = vevent.add(field) - dtfield.value = parser.parse(data[map_field]) - if tzval: - dtfield.params['TZID'] = [tzval.title()] + vevent.add(field).value = tools.ustr(data[map_field]) + elif map_type in ('datetime', 'date') and data[map_field]: + dtfield = vevent.add(field) + dtfield.value = parser.parse(data[map_field]) + if tzval: + dtfield.params['TZID'] = [tzval.title()] elif map_type == "timedelta": vevent.add(field).value = timedelta(hours=data[map_field]) elif map_type == "many2one": @@ -275,11 +275,13 @@ class CalDAV(object): def check_import(self, cr, uid, vals, context={}): ids = [] model_obj = self.pool.get(context.get('model')) + recur_pool = {} try: for val in vals: exists, r_id = uid2openobjectid(cr, val['id'], context.get('model'), \ val.get('recurrent_id')) if val.has_key('create_date'): val.pop('create_date') + u_id = val.get('id', None) val.pop('id') if exists and r_id: val.update({'recurrent_uid': exists}) @@ -289,8 +291,14 @@ class CalDAV(object): model_obj.write(cr, uid, [exists], val) ids.append(exists) else: - event_id = model_obj.create(cr, uid, val) - ids.append(event_id) + if u_id in recur_pool and val.get('recurrent_id'): + val.update({'recurrent_uid': recur_pool[u_id]}) + revent_id = model_obj.create(cr, uid, val) + ids.append(revent_id) + else: + event_id = model_obj.create(cr, uid, val) + recur_pool[u_id] = event_id + ids.append(event_id) except Exception, e: raise osv.except_osv(('Error !'), (str(e))) return ids @@ -369,6 +377,7 @@ class Calendar(CalDAV, osv.osv): def import_cal(self, cr, uid, content, data_id=None, context=None): if not context: context = {} + vals = [] ical_data = base64.decodestring(content) parsedCal = vobject.readOne(ical_data) if not data_id: @@ -385,11 +394,12 @@ class Calendar(CalDAV, osv.osv): }) self.__attribute__ = get_attribute_mapping(cr, uid, child.name.lower(), context=context) val = self.parse_ics(cr, uid, child, cal_children=cal_children, context=context) + vals.append(val) obj = self.pool.get(cal_children[child.name.lower()]) - if hasattr(obj, 'check_import'): - obj.check_import(cr, uid, [val], context=context) - else: - self.check_import(cr, uid, [val], context=context) + if hasattr(obj, 'check_import'): + obj.check_import(cr, uid, vals, context=context) + else: + self.check_import(cr, uid, vals, context=context) return {} Calendar() diff --git a/addons/crm_caldav/crm_caldav.py b/addons/crm_caldav/crm_caldav.py index a39088faeff..ee947aaf82f 100644 --- a/addons/crm_caldav/crm_caldav.py +++ b/addons/crm_caldav/crm_caldav.py @@ -23,11 +23,10 @@ from osv import fields, osv from crm import crm from caldav import caldav from base_calendar import base_calendar + class crm_meeting(osv.osv): _inherit = 'crm.meeting' - - def export_cal(self, cr, uid, ids, context={}): ids = map(lambda x: base_calendar.base_calendar_id2real_id(x), ids) event_data = self.read(cr, uid, ids) @@ -39,29 +38,7 @@ class crm_meeting(osv.osv): event_obj = self.pool.get('basic.calendar.event') vals = event_obj.import_cal(cr, uid, data, context=context) return self.check_import(cr, uid, vals, context=context) - - def check_import(self, cr, uid, vals, context={}): - ids = [] - for val in vals: - exists, r_id = caldav.uid2openobjectid(cr, val['id'], \ - self._name, val.get('recurrent_id')) - if val.has_key('create_date'): val.pop('create_date') - val['base_calendar_url'] = context.get('url') or '' - val.pop('id') - 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: - event_id = self.create(cr, uid, val) - ids.append(event_id) - return ids crm_meeting() - - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: