Merge lp:~syleam/openobject-addons/5.0-ics-predicable-fix into lp:openobject-addons/5.0

Proposed by Christophe CHAUVET
Status: Merged
Merge reported by: Harry (OpenERP)
Merged at revision: not available
Proposed branch: lp:~syleam/openobject-addons/5.0-ics-predicable-fix
Merge into: lp:openobject-addons/5.0
Diff against target: None lines
To merge this branch: bzr merge lp:~syleam/openobject-addons/5.0-ics-predicable-fix
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+5052@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'document_ics/document.py'
--- document_ics/document.py 2009-01-05 13:49:37 +0000
+++ document_ics/document.py 2009-03-30 20:15:45 +0000
@@ -28,6 +28,7 @@
28import datetime28import datetime
29import time29import time
30import random30import random
31import tools
3132
32ICS_TAGS = {33ICS_TAGS = {
33 'summary':'normal',34 'summary':'normal',
@@ -35,7 +36,7 @@
35 'dtstart':'date' ,36 'dtstart':'date' ,
36 'dtend':'date' ,37 'dtend':'date' ,
37 'created':'date' ,38 'created':'date' ,
38 'dt-stamp':'date' ,39 'dtstamp':'date' ,
39 'last-modified':'normal' ,40 'last-modified':'normal' ,
40 'url':'normal' ,41 'url':'normal' ,
41 'attendee':'multiple',42 'attendee':'multiple',
@@ -87,7 +88,7 @@
87 uuid = event.value88 uuid = event.value
88 if event.name.lower() in fields:89 if event.name.lower() in fields:
89 if ICS_TAGS[event.name.lower()]=='normal':90 if ICS_TAGS[event.name.lower()]=='normal':
90 result[fields[event.name.lower()]] = event.value.encode('utf8')91 result[fields[event.name.lower()]] = event.value
91 elif ICS_TAGS[event.name.lower()]=='date':92 elif ICS_TAGS[event.name.lower()]=='date':
92 result[fields[event.name.lower()]] = event.value.strftime('%Y-%m-%d %H:%M:%S')93 result[fields[event.name.lower()]] = event.value.strftime('%Y-%m-%d %H:%M:%S')
93 if not uuid:94 if not uuid:
@@ -105,6 +106,12 @@
105 return True106 return True
106107
107 def process_read_ics(self, cr, uid, node, context={}):108 def process_read_ics(self, cr, uid, node, context={}):
109 def ics_datetime(idate, short=False):
110 if short:
111 return datetime.date.fromtimestamp(time.mktime(time.strptime(idate, '%Y-%m-%d')))
112 else:
113 return datetime.datetime.strptime(idate, '%Y-%m-%d %H:%M:%S')
114
108 import vobject115 import vobject
109 obj_class = self.pool.get(node.content.ics_object_id.model)116 obj_class = self.pool.get(node.content.ics_object_id.model)
110 # Can be improved to use context and active_id !117 # Can be improved to use context and active_id !
@@ -116,20 +123,19 @@
116 for field in node.content.ics_field_ids:123 for field in node.content.ics_field_ids:
117 value = getattr(obj, field.field_id.name)124 value = getattr(obj, field.field_id.name)
118 if (not value) and field.name=='uid':125 if (not value) and field.name=='uid':
119 value = 'OpenERP-'+str(random.randint(1999999999, 9999999999))126 value = 'OpenERP-%s_%s@%s' % (node.content.ics_object_id.model, str(obj.id), cr.dbname,)
120 obj_class.write(cr, uid, [obj.id], {field.field_id.name: value})
121 if ICS_TAGS[field.name]=='normal':127 if ICS_TAGS[field.name]=='normal':
122 if type(value)==type(obj):128 if type(value)==type(obj):
123 value=value.name129 value=value.name
124 value = value or ''130 value = value or ''
125 event.add(field.name).value = value or ''131 event.add(field.name).value = value or ''
126 elif ICS_TAGS[field.name]=='date':132 elif ICS_TAGS[field.name]=='date' and value:
127 dt = value or time.strftime('%Y-%m-%d %H:%M:%S')133 if len(value)==10:
128 if len(dt)==10:134 value = ics_datetime(value, True)
129 dt = dt+' 09:00:00'135 else:
130 value = datetime.datetime.strptime(dt, '%Y-%m-%d %H:%M:%S')136 value = ics_datetime(value)
131 event.add(field.name).value = value137 event.add(field.name).value = value
132 s= StringIO.StringIO(cal.serialize().encode('utf8'))138 s= StringIO.StringIO(cal.serialize())
133 s.name = node139 s.name = node
134 cr.commit()140 cr.commit()
135 return s141 return s
@@ -140,6 +146,16 @@
140 _columns = {146 _columns = {
141 'code': fields.char('Calendar Code', size=64)147 'code': fields.char('Calendar Code', size=64)
142 }148 }
149
150 def copy(self, cr, uid, id, default=None, context=None):
151 """
152 code field must be unique in ICS file
153 """
154 if not default: default = {}
155 if not context: context = {}
156 default.update({'code': False, 'id': False})
157 return super(crm_case, self).copy(cr, uid, id, default, context)
158
143crm_case()159crm_case()
144160
145# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:161# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: