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
1=== modified file 'document_ics/document.py'
2--- document_ics/document.py 2009-01-05 13:49:37 +0000
3+++ document_ics/document.py 2009-03-30 20:15:45 +0000
4@@ -28,6 +28,7 @@
5 import datetime
6 import time
7 import random
8+import tools
9
10 ICS_TAGS = {
11 'summary':'normal',
12@@ -35,7 +36,7 @@
13 'dtstart':'date' ,
14 'dtend':'date' ,
15 'created':'date' ,
16- 'dt-stamp':'date' ,
17+ 'dtstamp':'date' ,
18 'last-modified':'normal' ,
19 'url':'normal' ,
20 'attendee':'multiple',
21@@ -87,7 +88,7 @@
22 uuid = event.value
23 if event.name.lower() in fields:
24 if ICS_TAGS[event.name.lower()]=='normal':
25- result[fields[event.name.lower()]] = event.value.encode('utf8')
26+ result[fields[event.name.lower()]] = event.value
27 elif ICS_TAGS[event.name.lower()]=='date':
28 result[fields[event.name.lower()]] = event.value.strftime('%Y-%m-%d %H:%M:%S')
29 if not uuid:
30@@ -105,6 +106,12 @@
31 return True
32
33 def process_read_ics(self, cr, uid, node, context={}):
34+ def ics_datetime(idate, short=False):
35+ if short:
36+ return datetime.date.fromtimestamp(time.mktime(time.strptime(idate, '%Y-%m-%d')))
37+ else:
38+ return datetime.datetime.strptime(idate, '%Y-%m-%d %H:%M:%S')
39+
40 import vobject
41 obj_class = self.pool.get(node.content.ics_object_id.model)
42 # Can be improved to use context and active_id !
43@@ -116,20 +123,19 @@
44 for field in node.content.ics_field_ids:
45 value = getattr(obj, field.field_id.name)
46 if (not value) and field.name=='uid':
47- value = 'OpenERP-'+str(random.randint(1999999999, 9999999999))
48- obj_class.write(cr, uid, [obj.id], {field.field_id.name: value})
49+ value = 'OpenERP-%s_%s@%s' % (node.content.ics_object_id.model, str(obj.id), cr.dbname,)
50 if ICS_TAGS[field.name]=='normal':
51 if type(value)==type(obj):
52 value=value.name
53 value = value or ''
54 event.add(field.name).value = value or ''
55- elif ICS_TAGS[field.name]=='date':
56- dt = value or time.strftime('%Y-%m-%d %H:%M:%S')
57- if len(dt)==10:
58- dt = dt+' 09:00:00'
59- value = datetime.datetime.strptime(dt, '%Y-%m-%d %H:%M:%S')
60+ elif ICS_TAGS[field.name]=='date' and value:
61+ if len(value)==10:
62+ value = ics_datetime(value, True)
63+ else:
64+ value = ics_datetime(value)
65 event.add(field.name).value = value
66- s= StringIO.StringIO(cal.serialize().encode('utf8'))
67+ s= StringIO.StringIO(cal.serialize())
68 s.name = node
69 cr.commit()
70 return s
71@@ -140,6 +146,16 @@
72 _columns = {
73 'code': fields.char('Calendar Code', size=64)
74 }
75+
76+ def copy(self, cr, uid, id, default=None, context=None):
77+ """
78+ code field must be unique in ICS file
79+ """
80+ if not default: default = {}
81+ if not context: context = {}
82+ default.update({'code': False, 'id': False})
83+ return super(crm_case, self).copy(cr, uid, id, default, context)
84+
85 crm_case()
86
87 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: