From f8cdd154616fccb0f87aa5fc5884dc5ff3c48b02 Mon Sep 17 00:00:00 2001 From: "Harry (Open ERP)" Date: Thu, 7 Jan 2010 20:05:43 +0530 Subject: [PATCH] [IMP+FIX] caldav, crm : caldav.alarm inherits from res.alarm, fix bug on recurrent on crm.meeting bzr revid: hmo@tinyerp.com-20100107143543-616twodd36utx01i --- addons/caldav/common.py | 27 +++++++-------------------- addons/crm/crm_meeting.py | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/addons/caldav/common.py b/addons/caldav/common.py index 7bf380103f4..afc7a6cb8c9 100644 --- a/addons/caldav/common.py +++ b/addons/caldav/common.py @@ -214,7 +214,7 @@ res_alarm() class calendar_alarm(osv.osv): _name = 'calendar.alarm' _description = 'Event alarm information' - + _inherits = {'res.alarm': "alarm_id"} __attribute__ = { 'action': {'field': 'action', 'type': 'text'}, 'description': {'field': 'name', 'type': 'text'}, @@ -227,9 +227,10 @@ class calendar_alarm(osv.osv): 'duration': {'field': 'duration', 'type': 'text'}, 'repeat': {'field': 'repeat', 'type': 'text'}, 'attach': {'field': 'attach', 'type': 'text'}, - } - - _columns = { + } + + _columns = { + 'alarm_id': fields.many2one('res.alarm', 'Basic Alarm', ondelete='cascade'), 'name': fields.char('Summary', size=124, help="""Contains the text to be used as the message subject for email or contains the text to be used for display"""), 'action': fields.selection([('audio', 'Audio'), ('display', 'Display'), \ @@ -237,17 +238,7 @@ or contains the text to be used for display"""), required=True, help="Defines the action to be invoked when an alarm is triggered"), 'description': fields.text('Description', help='Provides a more complete description of the calendar component, than that provided by the "SUMMARY" property'), 'attendee_ids': fields.many2many('calendar.attendee', 'alarm_attendee_rel', \ - 'alarm_id', 'attendee_id', 'Attendees', readonly=True), - 'trigger_occurs': fields.selection([('before', 'before'), ('after', 'after')], \ - 'Trigger time', required=True), - 'trigger_interval': fields.selection([('minutes', 'minutes'), ('hours', 'hours'), \ - ('days', 'days')], 'Trigger duration', required=True), - 'trigger_duration': fields.integer('Time', required=True), - 'trigger_related': fields.selection([('start', 'The event starts'), ('end', \ - 'The event ends')], 'Trigger Occures at', required=True), - 'duration': fields.integer('Duration', help="""Duration' and 'Repeat' \ -are both optional, but if one occurs, so MUST the other"""), - 'repeat': fields.integer('Repeat'), # TODO + 'alarm_id', 'attendee_id', 'Attendees', readonly=True), 'attach': fields.binary('Attachment', help="""* Points to a sound resource, which is rendered when the alarm is triggered for audio, * File which is intended to be sent as message attachments for email, * Points to a procedure resource, which is invoked when the alarm is triggered for procedure."""), @@ -266,11 +257,7 @@ are both optional, but if one occurs, so MUST the other"""), _defaults = { 'action': lambda *x: 'email', - 'state' : lambda *x: 'run', - 'trigger_interval': lambda *x: 'minutes', - 'trigger_duration': lambda *x: 5, - 'trigger_occurs': lambda *x: 'before', - 'trigger_related': lambda *x: 'start', + 'state' : lambda *x: 'run', } def create(self, cr, uid, vals, context={}): diff --git a/addons/crm/crm_meeting.py b/addons/crm/crm_meeting.py index 31a639c6be4..01b91bef73c 100644 --- a/addons/crm/crm_meeting.py +++ b/addons/crm/crm_meeting.py @@ -137,7 +137,7 @@ class crm_meeting(osv.osv): basic_alarm = meeting.alarm_id if basic_alarm and meeting.state in ('open'): vals = { - 'action': 'DISPLAY', + 'action': 'display', 'description': meeting.description, 'name': meeting.name, 'attendee_ids': [(6,0, map(lambda x:x.id, meeting.attendee_ids))], @@ -221,6 +221,10 @@ class crm_meeting(osv.osv): val.pop('id') if val.has_key('create_date'): val.pop('create_date') val['caldav_url'] = context.get('url') or '' + caldav_alarm_id = val['caldav_alarm_id'] + if caldav_alarm_id: + caldav_alarm = self.browse(cr, uid, caldav_alarm_id) + val['alarm_id'] = caldav_alarm.alarm_id if is_exists: self.write(cr, uid, [is_exists], val) else: @@ -229,8 +233,7 @@ class crm_meeting(osv.osv): def get_recurrent_ids(self, cr, uid, ids, start_date, until_date, limit=100): if not limit: - limit = 100 - + limit = 100 if ids and (start_date or until_date): cr.execute("select m.id, m.rrule, c.date, m.exdate from crm_meeting m\ join crm_case c on (c.id=m.inherit_case_id) \ @@ -255,9 +258,11 @@ class crm_meeting(osv.osv): rrule_str = data['rrule'] new_rrule_str = [] rrule_until_date = False + is_until = False for rule in rrule_str.split(';'): name, value = rule.split('=') if name == "UNTIL": + is_until = True value = parser.parse(value) rrule_until_date = parser.parse(value.strftime("%Y-%m-%d")) if until_date and until_date >= rrule_until_date: @@ -267,8 +272,14 @@ class crm_meeting(osv.osv): value = until_date new_rule = '%s=%s' % (name, value) new_rrule_str.append(new_rule) + if not is_until and until_date: + until_date = until_date.strftime("%Y%m%d%H%M%S") + value = until_date + name = "UNTIL" + new_rule = '%s=%s' % (name, value) + new_rrule_str.append(new_rule) new_rrule_str = ';'.join(new_rrule_str) - start_date = datetime.datetime.strptime(data['date'], "%Y-%m-%d %H:%M:%S") + start_date = datetime.datetime.strptime(data['date'], "%Y-%m-%d %H:%M:%S") rdates = event_obj.get_recurrent_dates(str(new_rrule_str), exdate, start_date) for rdate in rdates: idval = common.real_id2caldav_id(data['id'], rdate)