[FIX]: caldav, base_calendar: Updated alarm for event when its imported from .ics

bzr revid: rpa@tinyerp.com-20100701060516-kntaiwze8dxs29ei
This commit is contained in:
rpa (Open ERP) 2010-07-01 11:35:16 +05:30
parent 7394de4069
commit 913f68942e
2 changed files with 43 additions and 10 deletions

View File

@ -576,7 +576,7 @@ property or property parameter."),
if not vals.get("email") and vals.get("cn"):
cnval = vals.get("cn").split(':')
email = filter(lambda x:x.__contains__('@'), cnval)
vals['email'] = email[0]
vals['email'] = email and email[0] or ''
vals['cn'] = vals.get("cn")
res = super(calendar_attendee, self).create(cr, uid, vals, context)
return res
@ -629,6 +629,7 @@ true, it will allow you to hide the event alarm information without removing it.
if not context:
context = {}
alarm_obj = self.pool.get('calendar.alarm')
res_alarm_obj = self.pool.get('res.alarm')
ir_obj = self.pool.get('ir.model')
model_id = ir_obj.search(cr, uid, [('model', '=', model)])[0]
@ -636,6 +637,30 @@ true, it will allow you to hide the event alarm information without removing it.
for data in model_obj.browse(cr, uid, ids, context):
basic_alarm = data.alarm_id
cal_alarm = data.base_calendar_alarm_id
if (not basic_alarm and cal_alarm) or (basic_alarm and cal_alarm):
new_res_alarm = None
# Find for existing res.alarm
duration = cal_alarm.trigger_duration
interval = cal_alarm.trigger_interval
occurs = cal_alarm.trigger_occurs
related = cal_alarm.trigger_related
domain = [('trigger_duration', '=', duration), ('trigger_interval', '=', interval), ('trigger_occurs', '=', occurs), ('trigger_related', '=', related)]
alarm_ids = res_alarm_obj.search(cr, uid, domain, context=context)
if not alarm_ids:
val = {
'trigger_duration': duration,
'trigger_interval': interval,
'trigger_occurs': occurs,
'trigger_related': related,
'name': str(duration) + ' ' + str(interval) + ' ' + str(occurs)
}
new_res_alarm = res_alarm_obj.create(cr, uid, val, context=context)
else:
new_res_alarm = alarm_ids[0]
cr.execute('Update %s set base_calendar_alarm_id=%s, alarm_id=%s \
where id=%s' % (model_obj._table, \
cal_alarm.id, new_res_alarm, data.id))
if not context.get('alarm_id', False):
self.do_alarm_unlink(cr, uid, [data.id], model)
return True
@ -1463,7 +1488,7 @@ true, it will allow you to hide the event alarm information without removing it.
context = {}
res = super(calendar_event, self).copy(cr, uid, base_calendar_id2real_id(id), default, context)
alarm_obj = self.pool.get('res.alarm')
alarm_obj.do_alarm_create(cr, uid, [res], self._name, 'date')
alarm_obj.do_alarm_create(cr, uid, [res], self._name, 'date', context=context)
return res
@ -1514,7 +1539,7 @@ true, it will allow you to hide the event alarm information without removing it.
context = {}
res = super(calendar_event, self).create(cr, uid, vals, context)
alarm_obj = self.pool.get('res.alarm')
alarm_obj.do_alarm_create(cr, uid, [res], self._name, 'date')
alarm_obj.do_alarm_create(cr, uid, [res], self._name, 'date', context=context)
return res
calendar_event()

View File

@ -117,7 +117,7 @@ def get_attribute_mapping(cr, uid, calname, context={}):
res['uid']['type'] = "integer"
return res
def map_data(cr, uid, obj):
def map_data(cr, uid, obj, context=None):
""" Map Data
@param self: The object pointer
@param cr: the current row, from the database cursor,"""
@ -144,7 +144,7 @@ def map_data(cr, uid, obj):
model = obj.__attribute__[map_dict].get('object', False)
modobj = obj.pool.get(model)
for map_vall in map_val:
id = modobj.create(cr, uid, map_vall)
id = modobj.create(cr, uid, map_vall, context=context)
ids.append(id)
vals[field] = [(6, 0, ids)]
continue
@ -155,7 +155,15 @@ def map_data(cr, uid, obj):
continue
model = obj.__attribute__[map_dict].get('object', False)
modobj = obj.pool.get(model)
id = modobj.create(cr, uid, map_val)
# check if the record exists or not
key1 = map_val.keys()
value1 = map_val.values()
domain = [(key1[i], '=', value1[i]) for i in range(len(key1)) if value1[i]]
exist_id = modobj.search(cr, uid, domain, context=context)
if exist_id:
id = exist_id[0]
else:
id = modobj.create(cr, uid, map_val, context=context)
vals[field] = id
continue
if field_type == 'timedelta':
@ -245,7 +253,7 @@ class CalDAV(object):
if cal_data.params.get('X-VOBJ-ORIGINAL-TZID'):
self.ical_set('vtimezone', cal_data.params.get('X-VOBJ-ORIGINAL-TZID'), 'value')
self.ical_set(cal_data.name.lower(), cal_data.value, 'value')
vals = map_data(cr, uid, self)
vals = map_data(cr, uid, self, context=context)
return vals
def create_ics(self, cr, uid, datas, name, ical, context=None):
@ -874,7 +882,7 @@ class Timezone(CalDAV, osv.osv_memory):
if child.name.lower() == 'tzid':
tzname = child.value
self.ical_set(child.name.lower(), tzname, 'value')
vals = map_data(cr, uid, self)
vals = map_data(cr, uid, self, context=context)
return vals
Timezone()
@ -969,7 +977,7 @@ class Alarm(CalDAV, osv.osv_memory):
self.ical_set('trigger_related', child.params.get('related')[0].lower(), 'value')
else:
self.ical_set(child.name.lower(), child.value.lower(), 'value')
vals = map_data(cr, uid, self)
vals = map_data(cr, uid, self, context=context)
return vals
Alarm()
@ -1013,7 +1021,7 @@ class Attendee(CalDAV, osv.osv_memory):
self.ical_set(para.lower(), ical_data.params[para][0].lower(), 'value')
if not ical_data.params.get('CN'):
self.ical_set('cn', ical_data.value, 'value')
vals = map_data(cr, uid, self)
vals = map_data(cr, uid, self, context=context)
return vals
def export_cal(self, cr, uid, model, attendee_ids, vevent, context={}):