From e2c0a6665aa593c71bd06cbc311160538912db0d Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Thu, 21 Jan 2010 15:40:24 +0530 Subject: [PATCH] [IMP]: base_calendar, caldav: Improvement and Fixed problems in import/export .ics bzr revid: rpa@openerp.co.in-20100121101024-cr36ykm8z2aysxg7 --- addons/base_calendar/base_calendar.py | 18 +++++++++++------- addons/caldav/caldav.py | 4 ++-- addons/caldav/wizard/wizard_cal_export.py | 5 +++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/addons/base_calendar/base_calendar.py b/addons/base_calendar/base_calendar.py index 8972c54..9122c08 100644 --- a/addons/base_calendar/base_calendar.py +++ b/addons/base_calendar/base_calendar.py @@ -145,8 +145,6 @@ class CalDAV(object): val = ','.join(map(lambda x: x.strftime('%Y-%m-%d %H:%M:%S'), val)) else: val = val.strftime('%Y-%m-%d %H:%M:%S') - if valtype and valtype == 'integer' and val: - val = int(val) return val else: return self.__attribute__.get(name, None) @@ -194,7 +192,7 @@ class CalDAV(object): vevent = alarm_obj.export_ical(cr, uid, model, \ data[map_field][0], vevent, context=context) elif data[map_field]: - if map_type == "text": + if map_type in ("char", "text"): vevent.add(field).value = str(data[map_field]) elif map_type == 'datetime' and data[map_field]: if field in ('exdate'): @@ -205,13 +203,19 @@ class CalDAV(object): vevent.add(field).value = timedelta(hours=data[map_field]) elif map_type == "many2one": vevent.add(field).value = [data.get(map_field)[1]] - if self.__attribute__.get(field).has_key('mapping'): - for key1, val1 in self.ical_get(field, 'mapping').items(): - if val1 == data[map_field]: - vevent.add(field).value = key1 + elif map_type in ("float", "integer"): + vevent.add(field).value = [data.get(map_field)] + elif map_type == "selection": + if not self.ical_get(field, 'mapping'): + vevent.add(field).value = (data[map_field]).upper() + else: + for key1, val1 in self.ical_get(field, 'mapping').items(): + if val1 == data[map_field]: + vevent.add(field).value = key1 return ical def import_ical(self, cr, uid, ical_data): + self.__attribute__ = get_attribute_mapping(cr, uid, self._name) parsedCal = vobject.readOne(ical_data) att_data = [] res = [] diff --git a/addons/caldav/caldav.py b/addons/caldav/caldav.py index d693e09..e573998 100644 --- a/addons/caldav/caldav.py +++ b/addons/caldav/caldav.py @@ -733,7 +733,7 @@ class calendar_todo(osv.osv): obj_tm = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.project_time_mode_id if not val.has_key('planned_hours'): # 'Computes duration' in days - start = datetime.strptime(val['date_start'], '%Y-%m-%d %H:%M:%S') + start = datetime.strptime(val['date'], '%Y-%m-%d %H:%M:%S') end = datetime.strptime(val['date_deadline'], '%Y-%m-%d %H:%M:%S') diff = end - start plan = (diff.seconds/float(86400) + diff.days) * obj_tm.factor @@ -759,7 +759,7 @@ class calendar_todo(osv.osv): task.pop('planned_hours') tasks.append(task) todo_obj = self.pool.get('basic.calendar.todo') - ical = todo_obj.export_ical(cr, uid, tasks, {'model': 'project.task'}) + ical = todo_obj.export_ical(cr, uid, tasks, context={'model': self._name}) calendar_val = ical.serialize() calendar_val = calendar_val.replace('"', '').strip() return calendar_val diff --git a/addons/caldav/wizard/wizard_cal_export.py b/addons/caldav/wizard/wizard_cal_export.py index 4b32f02..5b89d87 100644 --- a/addons/caldav/wizard/wizard_cal_export.py +++ b/addons/caldav/wizard/wizard_cal_export.py @@ -51,13 +51,14 @@ class cal_event_export_wizard(wizard.interface): model_obj = pooler.get_pool(cr.dbname).get(model) calendar = model_obj.export_cal(cr, uid, data['ids'], context) return {'file_path': base64.encodestring(calendar), \ - 'name': 'OpenERP Events.ics'} + 'name': 'OpenERP %s.ics' % (model_obj._description)} states = { 'init': { 'actions': [_process_export_ics], 'result': {'type': 'form', 'arch':form1, 'fields':form1_fields, \ - 'state': [('end', '_Cancel', 'gtk-cancel'), ('end', 'Ok', 'gtk-ok')]}}, + 'state': [('end', '_Cancel', 'gtk-cancel'), \ + ('end', 'Ok', 'gtk-ok')]}}, } cal_event_export_wizard('caldav.event.export') -- 1.7.10.4