From cd05a92fba8010fedbf51c3b85029f64de45f419 Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Wed, 20 Jan 2010 14:21:57 +0530 Subject: [PATCH] [IMP]: caldav: Improvement for table name in query and fixed problem of updating alarm data bzr revid: rpa@openerp.co.in-20100120085157-w50ot6i2a3854gc8 --- addons/caldav/calendar.py | 21 +++++++++++++-------- addons/caldav/common.py | 19 ++++++++++--------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/addons/caldav/calendar.py b/addons/caldav/calendar.py index c746967692c..4e8fc12d481 100644 --- a/addons/caldav/calendar.py +++ b/addons/caldav/calendar.py @@ -127,8 +127,9 @@ class CalDAV(object): if not model: continue uidval = common.openobjectid2uid(cr, data[map_field], model) + model_obj = self.pool.get(model) cr.execute('select id from %s where recurrent_uid=%s' - % (model.replace('.', '_'), data[map_field])) + % (model_obj._table, data[map_field])) r_ids = map(lambda x: x[0], cr.fetchall()) if r_ids: rdata = self.pool.get(model).read(cr, uid, r_ids) @@ -139,11 +140,15 @@ class CalDAV(object): uidval = common.openobjectid2uid(cr, data['recurrent_uid'], model) vevent.add('uid').value = uidval elif field == 'attendee' and data[map_field]: + model = self.__attribute__[field].get('object', False) attendee_obj = self.pool.get('basic.calendar.attendee') - vevent = attendee_obj.export_ical(cr, uid, data[map_field], vevent, context=context) + vevent = attendee_obj.export_ical(cr, uid, model, \ + data[map_field], vevent, context=context) elif field == 'valarm' and data[map_field]: + model = self.__attribute__[field].get('object', False) alarm_obj = self.pool.get('basic.calendar.alarm') - vevent = alarm_obj.export_ical(cr, uid, data[map_field][0], vevent, context=context) + vevent = alarm_obj.export_ical(cr, uid, model, \ + data[map_field][0], vevent, context=context) elif data[map_field]: if map_type == "text": vevent.add(field).value = str(data[map_field]) @@ -341,9 +346,9 @@ class Alarm(CalDAV, osv.osv_memory): 'x-prop': None, } - def export_ical(self, cr, uid, alarm_id, vevent, context={}): + def export_ical(self, cr, uid, model, alarm_id, vevent, context={}): valarm = vevent.add('valarm') - alarm_object = self.pool.get('calendar.alarm') + alarm_object = self.pool.get(model) alarm_data = alarm_object.read(cr, uid, alarm_id, []) # Compute trigger data @@ -427,9 +432,9 @@ class Attendee(CalDAV, osv.osv_memory): vals = map_data(cr, uid, self) return vals - def export_ical(self, cr, uid, attendee_id, vevent, context={}): - attendee_object = self.pool.get('calendar.attendee') - for attendee in attendee_object.read(cr, uid, attendee_id, []): + def export_ical(self, cr, uid, model, attendee_ids, vevent, context={}): + attendee_object = self.pool.get(model) + for attendee in attendee_object.read(cr, uid, attendee_ids, []): attendee_add = vevent.add('attendee') for a_key, a_val in attendee_object.__attribute__.items(): if attendee[a_val['field']] and a_val['field'] != 'cn': diff --git a/addons/caldav/common.py b/addons/caldav/common.py index d82cc369f91..dc3794c0d32 100644 --- a/addons/caldav/common.py +++ b/addons/caldav/common.py @@ -19,7 +19,6 @@ # ############################################################################## - from datetime import datetime, timedelta from datetime import datetime, timedelta from dateutil import parser @@ -27,6 +26,7 @@ from osv import fields, osv from service import web_services from tools.translate import _ import base64 +import pooler import re import time @@ -63,9 +63,10 @@ def uid2openobjectid(cr, uidval, oomodel, rdate): return (False, None) else: model, id, dbname = wematch.groups() + model_obj = pooler.get_pool(cr.dbname).get(model) if (not model == oomodel) or (not dbname == cr.dbname): return (False, None) - qry = 'select distinct(id) from %s' % model.replace('.', '_') + qry = 'select distinct(id) from %s' % model_obj._table if rdate: qry += " where recurrent_id='%s'" % (rdate) cr.execute(qry) @@ -282,8 +283,8 @@ are both optional, but if one occurs, so MUST the other"""), 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] + ir_obj = self.pool.get('ir.model') + model_id = ir_obj.search(cr, uid, [('model', '=', model)])[0] model_obj = self.pool.get(model) for data in model_obj.browse(cr, uid, ids): @@ -309,8 +310,8 @@ are both optional, but if one occurs, so MUST the other"""), } 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)) + where id=%s' % (model_obj._table, \ + alarm_id, basic_alarm.id, data.id)) cr.commit() return True @@ -323,8 +324,8 @@ are both optional, but if one occurs, so MUST the other"""), 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 %s set caldav_alarm_id=NULL, \ - alarm_id=NULL where id=%s' % (self._table, datas.id)) + cr.execute('Update %s set caldav_alarm_id=NULL, alarm_id=NULL\ + where id=%s' % (model_obj._table, datas.id)) cr.commit() return True @@ -716,7 +717,7 @@ rule or repeating pattern for anexception to a recurrence set"), if not id in new_ids: new_ids.append(id) res = super(calendar_event, self).write(cr, uid, new_ids, vals, context=context) - if vals.get('alarm_id'): + if vals.has_key('alarm_id'): alarm_obj = self.pool.get('res.alarm') alarm_obj.do_alarm_create(cr, uid, new_ids, self._name, 'date') return res