diff --git a/addons/caldav/common.py b/addons/caldav/common.py index cb6150bd3e1..2573d37591a 100644 --- a/addons/caldav/common.py +++ b/addons/caldav/common.py @@ -24,15 +24,32 @@ from service import web_services from tools.translate import _ import re +months = {1:"January", 2:"February", 3:"March", 4:"April", 5:"May", 6:"June", \ + 7:"July", 8:"August", 9:"September", 10:"October", 11:"November", \ + 12:"December"} + def caldevIDs2readIDs(caldev_ID = None): if caldev_ID: if isinstance(caldev_ID, str): return int(caldev_ID.split('-')[0]) return caldev_ID -months = {1:"January", 2:"February", 3:"March", 4:"April", 5:"May", 6:"June", \ - 7:"July", 8:"August", 9:"September", 10:"October", 11:"November", \ - 12:"December"} +def uid2openobjectid(cr, uidval, oomodel): + __rege = re.compile(r'OpenERP-([\w|\.]+)_([0-9]+)@(\w+)$') + wematch = __rege.match(uidval.encode('utf8')) + if not wematch: +# raise osv.except_osv('Warning!!', "Cannot locate UID in %s" % val['id']) + return False + else: + model, id, dbname = wematch.groups() + if (not model == oomodel) or (not dbname == cr.dbname): + return False + cr.execute('select distinct(id) from %s' % model.replace('.', '_')) + ids = map(lambda x: str(x[0]), cr.fetchall()) + if id in ids: + return id + return False + class crm_caldav_attendee(osv.osv): _name = 'crm.caldav.attendee' diff --git a/addons/crm/crm_calendar.py b/addons/crm/crm_calendar.py index 186afc2b938..5a8e23c5101 100644 --- a/addons/crm/crm_calendar.py +++ b/addons/crm/crm_calendar.py @@ -187,7 +187,7 @@ class crm_case(osv.osv): return caendar_val def import_cal(self, cr, uid, ids, data, context={}): - file_content = base64.decodestring(data['form']['file_path']) + file_content = base64.decodestring(data) event_obj = self.pool.get('caldav.event') event_obj.__attribute__.update(self.__attribute__) @@ -203,9 +203,13 @@ class crm_case(osv.osv): # TODO: Select proper section section_id = self.pool.get('crm.case.section').search(cr, uid, [])[0] val.update({'section_id' : section_id}) + is_exists = common.uid2openobjectid(cr, val['id'], self._name ) val.pop('id') val.pop('create_date') - case_id = self.create(cr, uid, val) + if is_exists: + self.write(cr, uid, [is_exists], val) + else: + case_id = self.create(cr, uid, val) return {'count': len(vals)} def search(self, cr, uid, args, offset=0, limit=None, order=None, diff --git a/addons/crm/wizard/wizard_cal_import.py b/addons/crm/wizard/wizard_cal_import.py index 2c1bd8d8ee9..ebda878c200 100644 --- a/addons/crm/wizard/wizard_cal_import.py +++ b/addons/crm/wizard/wizard_cal_import.py @@ -53,7 +53,7 @@ class crm_cal_import_wizard(wizard.interface): def _process_imp_ics(self, cr, uid, data, context=None): case_obj = pooler.get_pool(cr.dbname).get('crm.case') - vals = case_obj.import_cal(cr, uid, data['ids'], data, context) + vals = case_obj.import_cal(cr, uid, data['ids'], data['form']['file_path'], context) global cnt cnt = 0 if vals: diff --git a/addons/project_calendar/project_calendar.py b/addons/project_calendar/project_calendar.py index 19fe51c6c43..4cce92c244f 100644 --- a/addons/project_calendar/project_calendar.py +++ b/addons/project_calendar/project_calendar.py @@ -99,7 +99,7 @@ class project_task(osv.osv): } def import_cal(self, cr, uid, ids, data, context={}): - file_content = base64.decodestring(data['form']['file_path']) + file_content = base64.decodestring(data) todo_obj = self.pool.get('caldav.todo') todo_obj.__attribute__.update(self.__attribute__) @@ -125,8 +125,13 @@ class project_task(osv.osv): # Converts timedelta into Project time unit val['planned_hours'] = (val['planned_hours'].seconds/float(86400) + \ val['planned_hours'].days) * obj_tm.factor + + is_exists = common.uid2openobjectid(cr, val['id'], self._name ) val.pop('id') - task_id = self.create(cr, uid, val) + if is_exists: + self.write(cr, uid, [is_exists], val) + else: + case_id = self.create(cr, uid, val) return {'count': len(vals)} def export_cal(self, cr, uid, ids, context={}): diff --git a/addons/project_calendar/wizard/wizard_cal_import.py b/addons/project_calendar/wizard/wizard_cal_import.py index dd65bc11574..d4a007e10a9 100644 --- a/addons/project_calendar/wizard/wizard_cal_import.py +++ b/addons/project_calendar/wizard/wizard_cal_import.py @@ -53,7 +53,7 @@ class project_cal_imp_wizard(wizard.interface): def _process_imp_ics(self, cr, uid, data, context=None): task_obj = pooler.get_pool(cr.dbname).get('project.task') - vals = task_obj.import_cal(cr, uid, data['ids'], data, context) + vals = task_obj.import_cal(cr, uid, data['ids'], data['form']['file_path'], context) global cnt cnt = 0 if vals: