[IMP]: Caldav: Implemented Alarm import from ics file
bzr revid: rpa@tinyerp.com-20091215134355-2jwdkdk2mdo4v4ee
This commit is contained in:
@@ -58,8 +58,12 @@ def map_data(cr, uid, obj):
|
||||
vals[field] = [(6, 0, ids)]
|
||||
continue
|
||||
if field_type == 'many2one':
|
||||
# TODO: Map field value to many2one object
|
||||
continue # For now
|
||||
id = None
|
||||
model = obj.__attribute__[map_dict].get('object', False)
|
||||
modobj = obj.pool.get(model)
|
||||
id = modobj.create(cr, uid, map_val)
|
||||
vals[field] = id
|
||||
continue
|
||||
vals[field] = map_val
|
||||
return vals
|
||||
|
||||
@@ -101,10 +105,15 @@ class CalDAV(object):
|
||||
att_data.append(attendee.import_ical(cr, uid, cal_data))
|
||||
self.ical_set(cal_data.name.lower(), att_data , 'value')
|
||||
continue
|
||||
if cal_data.name.lower() == 'valarm':
|
||||
alarm = self.pool.get('caldav.alarm')
|
||||
vals = alarm.import_ical(cr, uid, cal_data)
|
||||
self.ical_set(cal_data.name.lower(), vals , 'value')
|
||||
continue
|
||||
if cal_data.name.lower() in self.__attribute__:
|
||||
self.ical_set(cal_data.name.lower(), cal_data.value, 'value')
|
||||
vals = map_data(cr, uid, self)
|
||||
return vals
|
||||
return vals
|
||||
|
||||
|
||||
class Calendar(CalDAV, osv.osv_memory):
|
||||
@@ -307,9 +316,9 @@ class Timezone(CalDAV):
|
||||
if self.__attribute__.has_key(val.name.lower()):
|
||||
self.__attribute__[val.name] = val.value
|
||||
|
||||
class Alarm(CalDAV):
|
||||
class Alarm(CalDAV, osv.osv_memory):
|
||||
_name = 'caldav.alarm'
|
||||
__attribute__ = {
|
||||
|
||||
'action' : None, # Use: R-1, Type: Text, defines the action to be invoked when an alarm is triggered LIKE "AUDIO" / "DISPLAY" / "EMAIL" / "PROCEDURE"
|
||||
'description' : None, # Type: Text, Provides a more complete description of the calendar component, than that provided by the "SUMMARY" property. Use:- R-1 for DISPLAY,Use:- R-1 for EMAIL,Use:- R-1 for PROCEDURE
|
||||
'summary' : None, # Use: R-1, Type: Text Which contains the text to be used as the message subject. Use for EMAIL
|
||||
@@ -322,9 +331,36 @@ class Alarm(CalDAV):
|
||||
}
|
||||
|
||||
def import_ical(self, cr, uid, ical_data):
|
||||
for val in ical_data.getChildren():
|
||||
if self.__attribute__.has_key(val.name.lower()):
|
||||
self.__attribute__[val.name] = val.value
|
||||
for child in ical_data.getChildren():
|
||||
if child.name.lower() == 'trigger':
|
||||
seconds = child.value.seconds
|
||||
days = child.value.days
|
||||
diff = (days * 86400) + seconds
|
||||
duration = 'DAYS'
|
||||
related = 'BEFORE'
|
||||
if not seconds:
|
||||
interval = abs(days)
|
||||
related = days>0 and 'AFTER' or 'BEFORE'
|
||||
elif (abs(diff) / 3600) == 0:
|
||||
interval = abs(diff / 60)
|
||||
duration = 'MINUTES'
|
||||
related = days>=0 and 'AFTER' or 'BEFORE'
|
||||
else:
|
||||
interval = abs(diff / 3600)
|
||||
duration = 'HOURS'
|
||||
related = days>=0 and 'AFTER' or 'BEFORE'
|
||||
self.ical_set('trigger_interval', interval, 'value')
|
||||
self.ical_set('trigger_duration', duration, 'value')
|
||||
self.ical_set('trigger_related', related, 'value')
|
||||
if child.params:
|
||||
if child.params.get('RELATED'):
|
||||
self.ical_set('trigger_occurs', child.params.get('RELATED')[0].lower(), 'value')
|
||||
else:
|
||||
self.ical_set(child.name.lower(), child.value, 'value')
|
||||
vals = map_data(cr, uid, self)
|
||||
return vals
|
||||
|
||||
Alarm()
|
||||
|
||||
class Attendee(CalDAV, osv.osv_memory):
|
||||
_name = 'caldav.attendee'
|
||||
|
||||
@@ -99,8 +99,19 @@ crm_caldav_attendee()
|
||||
class crm_caldav_alarm(osv.osv):
|
||||
_name = 'crm.caldav.alarm'
|
||||
_description = 'Event alarm information'
|
||||
|
||||
|
||||
__attribute__ = {
|
||||
'action': {'field': 'action', 'type': 'text'},
|
||||
'description': {'field': 'name', 'type': 'text'},
|
||||
'summary': {'field': 'description', 'type': 'text'},
|
||||
'attendee': {'field': 'attendee', 'type': 'text'},
|
||||
'trigger_related': {'field': 'trigger_related', 'type': 'text'}, # Check with separated fields
|
||||
'trigger_duration': {'field': 'trigger_duration', 'type': 'text'},
|
||||
'trigger_occurs': {'field': 'trigger_occurs', 'type': 'text'},
|
||||
'trigger_interval': {'field': 'trigger_interval', 'type': 'text'},
|
||||
'duration': {'field': 'duration', 'type': 'text'},
|
||||
'repeat': {'field': 'repeat', 'type': 'text'},
|
||||
'attach': {'field': 'attach', 'type': 'text'},
|
||||
}
|
||||
|
||||
_columns = {
|
||||
@@ -115,7 +126,7 @@ class crm_caldav_alarm(osv.osv):
|
||||
'trigger_duration' : fields.selection([('MINUTES', 'MINUTES'), ('HOURS', 'HOURS'), \
|
||||
('DAYS', 'DAYS')], 'Trugger duration', required=True),
|
||||
'trigger_interval' : fields.integer('TIme' , required=True),
|
||||
'trigger_occurs' : fields.selection([('starts', 'The event starts'), ('ends', \
|
||||
'trigger_occurs' : fields.selection([('start', 'The event starts'), ('end', \
|
||||
'The event ends')], 'Trigger Occures at', required=True),
|
||||
'duration' : fields.integer('Duration'),
|
||||
'repeat' : fields.integer('Repeat'), # TODO
|
||||
@@ -144,7 +155,7 @@ class crm_case(osv.osv):
|
||||
'dtstart' : {'field':'date', 'type':'datetime'},
|
||||
#'last-mod' : {'field':'write_date', 'type':'datetime'},
|
||||
'location' : {'field':'location', 'type':'text'},
|
||||
'organizer' : {'field':'partner_id', 'sub-field':'name', 'type':'many2one'},
|
||||
# 'organizer' : {'field':'partner_id', 'sub-field':'name', 'type':'many2one'},
|
||||
'priority' : {'field':'priority', 'type':'int'},
|
||||
'dtstamp' : {'field':'date', 'type':'datetime'},
|
||||
'seq' : None,
|
||||
@@ -172,6 +183,7 @@ class crm_case(osv.osv):
|
||||
'x-openobject-model' : {'value':_name, 'type':'text'},
|
||||
# 'duration' : {'field':'duration'},
|
||||
'dtend' : {'field':'date_closed', 'type':'datetime'},
|
||||
'valarm' : {'field':'alarm_id', 'type':'many2one', 'object' : 'crm.caldav.alarm'},
|
||||
}
|
||||
|
||||
def _get_location(self, cr, uid, ids, name, arg, context=None):
|
||||
@@ -321,6 +333,10 @@ class crm_case(osv.osv):
|
||||
crm_attendee = self.pool.get('crm.caldav.attendee')
|
||||
attendee_obj.__attribute__.update(crm_attendee.__attribute__)
|
||||
|
||||
alarm_obj = self.pool.get('caldav.alarm')
|
||||
crm_alarm = self.pool.get('crm.caldav.alarm')
|
||||
alarm_obj.__attribute__.update(crm_alarm.__attribute__)
|
||||
|
||||
vals = event_obj.import_ical(cr, uid, file_content)
|
||||
# TODO: Select proper section
|
||||
section_id = self.pool.get('crm.case.section').search(cr, uid, [])[0]
|
||||
|
||||
Reference in New Issue
Block a user