[IMP]: Caldav+crm+project_calendar: Improvement for importing more than one event and tasks, Set proper message after import
bzr revid: rpa@tinyerp.com-20091221094900-s4wy1qec4hff4dfo
This commit is contained in:
parent
6ff8fbdabb
commit
fa4d7a2bc9
|
@ -100,6 +100,12 @@ class CalDAV(object):
|
|||
else:
|
||||
return self.__attribute__.get(name, None)
|
||||
|
||||
def ical_reset(self, type):
|
||||
for name in self.__attribute__:
|
||||
if self.__attribute__[name]:
|
||||
self.__attribute__[name][type] = None
|
||||
return True
|
||||
|
||||
def export_ical(self, cr, uid, datas, vobj=None):
|
||||
ical = vobject.iCalendar()
|
||||
for data in datas:
|
||||
|
@ -129,7 +135,7 @@ class CalDAV(object):
|
|||
def import_ical(self, cr, uid, ical_data):
|
||||
parsedCal = vobject.readOne(ical_data)
|
||||
att_data = []
|
||||
todo_data = []
|
||||
res = []
|
||||
for child in parsedCal.getChildren():
|
||||
for cal_data in child.getChildren():
|
||||
if cal_data.name.lower() == 'attendee':
|
||||
|
@ -144,8 +150,10 @@ class CalDAV(object):
|
|||
continue
|
||||
if cal_data.name.lower() in self.__attribute__:
|
||||
self.ical_set(cal_data.name.lower(), cal_data.value, 'value')
|
||||
vals = map_data(cr, uid, self)
|
||||
return vals
|
||||
vals = map_data(cr, uid, self)
|
||||
if vals : res.append(vals)
|
||||
self.ical_reset('value')
|
||||
return res
|
||||
|
||||
|
||||
class Calendar(CalDAV, osv.osv_memory):
|
||||
|
|
|
@ -204,15 +204,15 @@ class crm_case(osv.osv):
|
|||
alarm_obj = self.pool.get('caldav.alarm')
|
||||
crm_alarm = self.pool.get('crm.caldav.alarm')
|
||||
alarm_obj.__attribute__.update(crm_alarm.__attribute__)
|
||||
|
||||
vals = event_obj.import_ical(cr, uid, file_content)
|
||||
# TODO: Select proper section
|
||||
section_id = self.pool.get('crm.case.section').search(cr, uid, [])[0]
|
||||
vals.update({'section_id' : section_id})
|
||||
vals.pop('id')
|
||||
vals.pop('create_date')
|
||||
case_id = self.create(cr, uid, vals)
|
||||
return
|
||||
for val in vals:
|
||||
# TODO: Select proper section
|
||||
section_id = self.pool.get('crm.case.section').search(cr, uid, [])[0]
|
||||
val.update({'section_id' : section_id})
|
||||
val.pop('id')
|
||||
val.pop('create_date')
|
||||
case_id = self.create(cr, uid, val)
|
||||
return {'count': len(vals)}
|
||||
|
||||
def search(self, cr, uid, args, offset=0, limit=None, order=None,
|
||||
context=None, count=False):
|
||||
|
|
|
@ -19,14 +19,9 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
import tools
|
||||
import wizard
|
||||
import os
|
||||
import mx.DateTime
|
||||
import base64
|
||||
import pooler
|
||||
import vobject
|
||||
|
||||
|
||||
class crm_cal_export_wizard(wizard.interface):
|
||||
|
@ -53,8 +48,8 @@ class crm_cal_export_wizard(wizard.interface):
|
|||
states = {
|
||||
'init': {
|
||||
'actions': [_process_export_ics],
|
||||
'result': {'type': 'form', 'arch':form1, 'fields':form1_fields, 'state': [('end', '_Cancel', 'gtk-cancel'), ('end', 'Ok', 'gtk-ok')]}
|
||||
},
|
||||
'result': {'type': 'form', 'arch':form1, 'fields':form1_fields, \
|
||||
'state': [('end', '_Cancel', 'gtk-cancel'), ('end', 'Ok', 'gtk-ok')]}},
|
||||
}
|
||||
|
||||
crm_cal_export_wizard('caldav.crm.export')
|
||||
|
|
|
@ -19,14 +19,8 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
import tools
|
||||
import wizard
|
||||
import os
|
||||
import mx.DateTime
|
||||
import base64
|
||||
import pooler
|
||||
import vobject
|
||||
|
||||
|
||||
class crm_cal_import_wizard(wizard.interface):
|
||||
|
@ -40,25 +34,49 @@ class crm_cal_import_wizard(wizard.interface):
|
|||
'file_path': {
|
||||
'string': 'Select ICS file',
|
||||
'type': 'binary',
|
||||
'required' : True,
|
||||
'filters' : '*.ics'
|
||||
'required': True,
|
||||
'filters': '*.ics'
|
||||
}
|
||||
}
|
||||
display = '''<?xml version="1.0"?>
|
||||
<form string="Import Message">
|
||||
<field name="msg" colspan="4" width="300" nolabel="1"/>
|
||||
</form>'''
|
||||
|
||||
def _process_import_ics(self, cr, uid, data, context=None):
|
||||
display_fields = {
|
||||
'msg': {
|
||||
'string': '',
|
||||
'type': 'text',
|
||||
'readonly': True,
|
||||
}
|
||||
}
|
||||
|
||||
def _process_imp_ics(self, cr, uid, data, context=None):
|
||||
case_obj = pooler.get_pool(cr.dbname).get('crm.case')
|
||||
case_obj.import_cal(cr, uid, data['ids'], data, context)
|
||||
vals = case_obj.import_cal(cr, uid, data['ids'], data, context)
|
||||
if vals:
|
||||
global cnt
|
||||
cnt = vals['count']
|
||||
return {}
|
||||
|
||||
def _result_set(self, cr, uid, data, context=None):
|
||||
return {'msg': 'Imported %s Event(s)' % cnt}
|
||||
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [],
|
||||
'result': {'type': 'form', 'arch':form1, 'fields':form1_fields, 'state': [('end', '_Cancel', 'gtk-cancel'), ('open', '_Import', 'gtk-ok')]}
|
||||
'result': {'type': 'form', 'arch': form1, 'fields': form1_fields, \
|
||||
'state': [('end', '_Cancel', 'gtk-cancel'), ('open', '_Import', 'gtk-ok')]}
|
||||
},
|
||||
'open': {
|
||||
'actions': [],
|
||||
'result': {'type': 'action', 'action':_process_import_ics, 'state':'end'}
|
||||
}
|
||||
'result': {'type': 'action', 'action': _process_imp_ics, 'state': 'display'}
|
||||
},
|
||||
'display': {
|
||||
'actions': [_result_set],
|
||||
'result': {'type': 'form', 'arch': display, 'fields': display_fields, \
|
||||
'state': [('end', 'Ok', 'gtk-ok')]}
|
||||
},
|
||||
}
|
||||
|
||||
crm_cal_import_wizard('caldav.crm.import')
|
||||
|
|
|
@ -111,17 +111,13 @@ class project_task(osv.osv):
|
|||
alarm_obj.__attribute__.update(crm_alarm.__attribute__)
|
||||
|
||||
vals = todo_obj.import_ical(cr, uid, file_content)
|
||||
if not vals.has_key('duration'):
|
||||
# 'Compute duration'
|
||||
vals['planned_hours'] = 16
|
||||
# start = datetime.strptime(vals.get('date_start'), '%Y-%m-%d %H:%M:%S')
|
||||
# end = datetime.strptime(vals.get('date_deadline'), '%Y-%m-%d %H:%M:%S')
|
||||
# difference = float((end - start).seconds) / 3600
|
||||
## minutes, seconds = divmod(difference.seconds, 60)
|
||||
## hours, minutes = divmod(minutes, 60)
|
||||
vals.pop('id')
|
||||
task_id = self.create(cr, uid, vals)
|
||||
return
|
||||
for val in vals:
|
||||
if not val.has_key('duration'):
|
||||
# 'Compute duration'
|
||||
val['planned_hours'] = 16
|
||||
val.pop('id')
|
||||
task_id = self.create(cr, uid, val)
|
||||
return {'count': len(vals)}
|
||||
|
||||
def export_cal(self, cr, uid, ids, context={}):
|
||||
task_data = self.read(cr, uid, ids, [], context ={'read': True})
|
||||
|
|
|
@ -19,14 +19,9 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
import tools
|
||||
import wizard
|
||||
import os
|
||||
import mx.DateTime
|
||||
import base64
|
||||
import pooler
|
||||
import vobject
|
||||
|
||||
|
||||
class project_cal_export_wizard(wizard.interface):
|
||||
|
|
|
@ -19,15 +19,8 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
import tools
|
||||
import wizard
|
||||
import os
|
||||
import mx.DateTime
|
||||
import base64
|
||||
import pooler
|
||||
import vobject
|
||||
|
||||
|
||||
class project_cal_imp_wizard(wizard.interface):
|
||||
form1 = '''<?xml version="1.0"?>
|
||||
|
@ -44,22 +37,46 @@ class project_cal_imp_wizard(wizard.interface):
|
|||
'filters': '*.ics'
|
||||
}
|
||||
}
|
||||
display = '''<?xml version="1.0"?>
|
||||
<form string="Import Message">
|
||||
<field name="msg" colspan="4" width="300" nolabel="1"/>
|
||||
</form>'''
|
||||
|
||||
display_fields = {
|
||||
'msg': {
|
||||
'string': '',
|
||||
'type': 'text',
|
||||
'readonly': True,
|
||||
'default': 'Imported %s Tasks'
|
||||
}
|
||||
}
|
||||
|
||||
def _process_imp_ics(self, cr, uid, data, context=None):
|
||||
task_obj = pooler.get_pool(cr.dbname).get('project.task')
|
||||
task_obj.import_cal(cr, uid, data['ids'], data, context)
|
||||
vals = task_obj.import_cal(cr, uid, data['ids'], data, context)
|
||||
if vals:
|
||||
global cnt
|
||||
cnt = vals['count']
|
||||
return {}
|
||||
|
||||
def _result_set(self, cr, uid, data, context=None):
|
||||
return {'msg': 'Imported %s Task(s)' % cnt}
|
||||
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [],
|
||||
'result': {'type': 'form', 'arch':form1, 'fields':form1_fields, \
|
||||
'result': {'type': 'form', 'arch': form1, 'fields': form1_fields, \
|
||||
'state': [('end', '_Cancel', 'gtk-cancel'), ('open', '_Import', 'gtk-ok')]}
|
||||
},
|
||||
'open': {
|
||||
'actions': [],
|
||||
'result': {'type': 'action', 'action':_process_imp_ics, 'state':'end'}
|
||||
}
|
||||
'result': {'type': 'action', 'action': _process_imp_ics, 'state': 'display'}
|
||||
},
|
||||
'display': {
|
||||
'actions': [_result_set],
|
||||
'result': {'type': 'form', 'arch': display, 'fields': display_fields, \
|
||||
'state': [('end', 'Ok', 'gtk-ok')]}
|
||||
},
|
||||
}
|
||||
|
||||
project_cal_imp_wizard('caldav.project.import')
|
||||
|
|
Loading…
Reference in New Issue