[IMP]: crm, caldav, project_calendar: Moved function for alarm maintenance to caldav common, Fixed problem of wrong data in attendee export

bzr revid: rpa@openerp.co.in-20100113132933-2a6vc4urg7gcgvf6
This commit is contained in:
rpa (Open ERP) 2010-01-13 18:59:33 +05:30
parent c5ba1c2fcb
commit 61880aa6ea
4 changed files with 66 additions and 52 deletions

View File

@ -422,11 +422,14 @@ class Attendee(CalDAV, osv.osv_memory):
for attendee in attendee_object.read(cr, uid, attendee_id, []):
attendee_add = vevent.add('attendee')
for a_key, a_val in attendee_object.__attribute__.items():
if attendee[a_val['field']]:
if attendee[a_val['field']] and a_val['field'] != 'cn':
if a_val['type'] == 'text':
attendee_add.params[a_key] = [str(attendee[a_val['field']])]
elif a_val['type'] == 'boolean':
attendee_add.params[a_key] = [str(attendee[a_val['field']])]
if a_val['field'] == 'cn':
cn_val = [str(attendee[a_val['field']])]
attendee_add.params['CN']= cn_val
return vevent
Attendee()

View File

@ -268,6 +268,54 @@ are both optional, but if one occurs, so MUST the other"""),
'active': lambda *x: 1,
}
def do_alarm_create(self, cr, uid, ids, model, date, context={}):
alarm_obj = self.pool.get('calendar.alarm')
model_obj = self.pool.get('ir.model')
model_id = model_obj.search(cr, uid, [('model', '=', model)])[0]
model_obj = self.pool.get(model)
for data in model_obj.browse(cr, uid, ids):
basic_alarm = data.alarm_id
self.do_alarm_unlink(cr, uid, [data.id], model)
if basic_alarm:
vals = {
'action': 'display',
'description': data.description,
'name': data.name,
'attendee_ids': [(6, 0, map(lambda x:x.id, data.attendee_ids))],
'trigger_related': basic_alarm.trigger_related,
'trigger_duration': basic_alarm.trigger_duration,
'trigger_occurs': basic_alarm.trigger_occurs,
'trigger_interval': basic_alarm.trigger_interval,
'duration': basic_alarm.duration,
'repeat': basic_alarm.repeat,
'state': 'run',
'event_date': data[date],
'res_id': data.id,
'model_id': model_id,
'user_id': uid
}
alarm_id = alarm_obj.create(cr, uid, vals)
cr.execute('Update %s set caldav_alarm_id=%s, alarm_id=%s \
where id=%s' % (model.replace('.', '_'), \
alarm_id, basic_alarm.id, data.id))
cr.commit()
return True
def do_alarm_unlink(self, cr, uid, ids, model, context={}):
alarm_obj = self.pool.get('calendar.alarm')
ir_obj = self.pool.get('ir.model')
model_id = ir_obj.search(cr, uid, [('model', '=', model)])[0]
model_obj = self.pool.get(model)
for datas in model_obj.browse(cr, uid, ids):
alarm_ids = alarm_obj.search(cr, uid, [('model_id', '=', model_id), ('res_id', '=', datas.id)])
if alarm_ids and len(alarm_ids):
alarm_obj.unlink(cr, uid, alarm_ids)
cr.execute('Update crm_meeting set caldav_alarm_id=NULL, \
alarm_id=NULL where id=%s' % (datas.id))
cr.commit()
return True
res_alarm()
class calendar_alarm(osv.osv):

View File

@ -68,7 +68,7 @@ class crm_meeting(osv.osv):
'url': {'field': 'caldav_url', 'type': 'text'},
'recurid': None,
# 'attach': {'field': 'attachment_ids', 'sub-field': 'datas', 'type': 'list'},
'attendee': {'field': 'attendee_ids', 'type': 'many2many', 'object': 'crm.caldav.attendee'},
'attendee': {'field': 'attendee_ids', 'type': 'many2many', 'object': 'calendar.attendee'},
'categories': {'field': 'categ_id', 'type': 'many2one', 'object': 'crm.meeting.categ'},
'comment': None,
'contact': None,
@ -158,51 +158,6 @@ rule or repeating pattern for anexception to a recurrence set"),
'show_as': lambda *a: 'busy',
}
def do_alarm_create(self, cr, uid, ids, context={}):
alarm_obj = self.pool.get('calendar.alarm')
model_obj = self.pool.get('ir.model')
model_id = model_obj.search(cr, uid, [('model', '=', self._name)])[0]
for meeting in self.browse(cr, uid, ids):
basic_alarm = meeting.alarm_id
self.do_alarm_unlink(cr, uid, [meeting.id])
if basic_alarm:
vals = {
'action': 'display',
'description': meeting.description,
'name': meeting.name,
'attendee_ids': [(6, 0, map(lambda x:x.id, meeting.attendee_ids))],
'trigger_related': basic_alarm.trigger_related,
'trigger_duration': basic_alarm.trigger_duration,
'trigger_occurs': basic_alarm.trigger_occurs,
'trigger_interval': basic_alarm.trigger_interval,
'duration': basic_alarm.duration,
'repeat': basic_alarm.repeat,
'state': 'run',
'event_date': meeting.date,
'res_id': meeting.id,
'model_id': model_id,
'user_id': uid
}
alarm_id = alarm_obj.create(cr, uid, vals)
cr.execute('Update crm_meeting set caldav_alarm_id=%s, \
alarm_id=%s where id=%s' % (alarm_id, basic_alarm.id, meeting.id))
cr.commit()
return True
def do_alarm_unlink(self, cr, uid, ids, context={}):
alarm_obj = self.pool.get('calendar.alarm')
model_obj = self.pool.get('ir.model')
model_id = model_obj.search(cr, uid, [('model', '=', self._name)])[0]
for meeting in self.browse(cr, uid, ids):
alarm_ids = alarm_obj.search(cr, uid, [('model_id', '=', model_id), ('res_id', '=', meeting.id)])
if alarm_ids and len(alarm_ids):
alarm_obj.unlink(cr, uid, alarm_ids)
cr.execute('Update crm_meeting set caldav_alarm_id=NULL, \
alarm_id=NULL where id=%s' % (meeting.id))
cr.commit()
return True
def on_change_duration(self, cr, uid, id, date, duration):
if not date:
return {}
@ -355,7 +310,8 @@ rule or repeating pattern for anexception to a recurrence set"),
new_ids.append(id)
res = super(crm_meeting, self).write(cr, uid, new_ids, vals, context=context)
if vals.get('alarm_id'):
self.do_alarm_create(cr, uid, new_ids)
alarm_obj = self.pool.get('res.alarm')
alarm_obj.do_alarm_create(cr, uid, new_ids, self._name, 'date')
return res
def browse(self, cr, uid, ids, context=None, list_class=None, fields_process={}):
@ -393,7 +349,8 @@ rule or repeating pattern for anexception to a recurrence set"),
def copy(self, cr, uid, id, default=None, context={}):
res = super(crm_meeting, self).copy(cr, uid, common.caldav_id2real_id(id), default, context)
self.do_alarm_create(cr, uid, [res])
alarm_obj = self.pool.get('res.alarm')
alarm_obj.do_alarm_create(cr, uid, [res], self._name, 'date')
return res
def unlink(self, cr, uid, ids, context=None):
@ -421,7 +378,8 @@ rule or repeating pattern for anexception to a recurrence set"),
def create(self, cr, uid, vals, context={}):
res = super(crm_meeting, self).create(cr, uid, vals, context)
self.do_alarm_create(cr, uid, [res])
alarm_obj = self.pool.get('res.alarm')
alarm_obj.do_alarm_create(cr, uid, [res], self._name, 'date')
return res

View File

@ -85,7 +85,6 @@ defines the list of date/time exceptions for arecurring calendar component."),
'rrule': {'field': 'rrule', 'type': 'text'},
'valarm': {'field':'caldav_alarm_id', 'type':'many2one', 'object': 'calendar.alarm'},
}
def onchange_rrule_type(self, cr, uid, ids, type, *args, **argv):
if type == 'none':
return {'value': {'rrule': ''}}
@ -276,6 +275,9 @@ defines the list of date/time exceptions for arecurring calendar component."),
if not id in new_ids:
new_ids.append(id)
res = super(project_task, self).write(cr, uid, new_ids, vals, context=context)
if vals.get('alarm_id'):
alarm_obj = self.pool.get('res.alarm')
alarm_obj.do_alarm_create(cr, uid, new_ids, self._name, 'date_start')
return res
def browse(self, cr, uid, ids, context=None, list_class=None, fields_process={}):
@ -290,7 +292,10 @@ defines the list of date/time exceptions for arecurring calendar component."),
return res
def copy(self, cr, uid, id, default=None, context={}):
return super(project_task, self).copy(cr, uid, common.caldav_id2real_id(id), default, context)
res = super(project_task, self).copy(cr, uid, common.caldav_id2real_id(id), default, context)
alarm_obj = self.pool.get('res.alarm')
alarm_obj.do_alarm_create(cr, uid, [res], self._name, 'date_start')
return res
def unlink(self, cr, uid, ids, context=None):
for id in ids: