1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import osv, fields
23 from tools import config
26 from tools.translate import _
28 class caldav_browse(osv.osv_memory):
33 * Webdav server that provides remote access to calendar
34 * Synchronisation of calendar using WebDAV
35 * Customize calendar event and todo attribute with any of OpenERP model
36 * Provides iCal Import/Export functionality
38 To access Calendars using CalDAV clients, point them to:
39 http://HOSTNAME:PORT/webdav/DATABASE_NAME/calendars/users/USERNAME/c
41 To access OpenERP Calendar using WebCal to remote site use the URL like:
42 http://HOSTNAME:PORT/webdav/DATABASE_NAME/Calendars/CALENDAR_NAME.ics
45 HOSTNAME: Host on which OpenERP server(With webdav) is running
46 PORT : Port on which OpenERP server is running (By Default : 8069)
47 DATABASE_NAME: Name of database on which OpenERP Calendar is created
48 CALENDAR_NAME: Name of calendar to access
54 For SSL specific configuration see the documentation below
56 Now, to setup the calendars, you need to:
58 1. Click on the "Settings" and go to the "Mail, Contacts, Calendars" page.
59 2. Go to "Add account..."
61 4. From the "Calendars" group, select "Add CalDAV Account"
63 5. Enter the host's name
64 (ie : if the url is http://openerp.com:8069/webdav/db_1/calendars/ , openerp.com is the host)
66 6. Fill Username and password with your openerp login and password
68 7. As a description, you can either leave the server's name or
69 something like "OpenERP calendars".
71 9. If you are not using a SSL server, you'll get an error, do not worry and push "Continue"
73 10. Then click to "Advanced Settings" to specify the right
76 11. Specify the port for the OpenERP server: 8071 for SSL, 8069 without.
78 12. Set the "Account URL" to the right path of the OpenERP webdav:
79 the url given by the wizard (ie : http://my.server.ip:8069/webdav/dbname/calendars/ )
81 11. Click on Done. The phone will hopefully connect to the OpenERP server
82 and verify it can use the account.
84 12. Go to the main menu of the iPhone and enter the Calendar application.
85 Your OpenERP calendars will be visible inside the selection of the
87 Note that when creating a new calendar entry, you will have to specify
88 which calendar it should be saved at.
92 IF you need SSL (and your certificate is not a verified one, as usual),
93 then you first will need to let the iPhone trust that. Follow these
96 s1. Open Safari and enter the https location of the OpenERP server:
97 https://my.server.ip:8071/
98 (assuming you have the server at "my.server.ip" and the HTTPS port
100 s2. Safari will try to connect and issue a warning about the certificate
101 used. Inspect the certificate and click "Accept" so that iPhone
107 There is no buit-in way to synchronize calendar with caldav.
108 So you need to install a third part software : Calendar (CalDav)
109 for now it's the only one
114 1. Open Calendar Sync
115 I'll get an interface with 2 tabs
116 Stay on the first one
118 2. CaDAV Calendar URL : put the URL given above (ie : http://host.com:8069/webdav/db/calendars/users/demo/c/Meetings)
120 3. Put your openerp username and password
122 4. If your server don't use SSL, you'll get a warnign, say "Yes"
124 5. Then you can synchronize manually or custom the settings to synchronize every x minutes.
129 1. Go to Calendar View
131 2. File -> New -> Calendar
135 - name : Whaterver you want (ie : Meeting)
136 - url : http://HOST:PORT/webdav/DB_NAME/calendars/users/USER/c/Meetings (ie : http://localhost:8069/webdav/db_1/calendars/users/demo/c/Meetings) the one given on the top of this window
138 - Username : Your username (ie : Demo)
139 - Refresh : everytime you want that evolution synchronize the data with the server
141 4. Click ok and give your openerp password
143 5. A new calendar named with the name you gave should appear on the left side.
147 'thunderbird' : _("""
150 If you are using thunderbird, first you need to install the lightning module
151 http://www.mozilla.org/projects/calendar/lightning/
156 1. Go to Calendar View
158 2. File -> New Calendar
160 3. Chosse "On the Network"
162 4. for format choose CalDav
163 and as location the url given above (ie : http://host.com:8069/webdav/db/calendars/users/demo/c/Meetings)
165 5. Choose a name and a color for the Calendar, and we advice you to uncheck "alarm"
167 6. Then put your openerp login and password (to give the password only check the box "Use password Manager to remember this password"
169 7. Then Finish, your meetings should appear now in your calendar view
174 _name = 'caldav.browse'
175 _description = 'Caldav Browse'
178 'url' : fields.char('Caldav Server', size=264, required=True, help="Url of the caldav server, use for synchronization"),
179 #'doc_link':fields.char('Caldav Documentation', size="264", help="The link to Caldav Online Documentation.", readonly=True),
180 'description':fields.text('Description', readonly=True)
183 def default_get(self, cr, uid, fields, context=None):
188 if not config.get('xmlrpc'):
189 if not config.get('netrpc'):
191 host = config.get('xmlrpcs_interface', None)
192 port = config.get('xmlrpcs_port', 8071)
194 host = config.get('netrpc_interface', None)
195 port = config.get('netrpc_port',8070)
197 host = config.get('xmlrpc_interface', None)
198 port = config.get('xmlrpc_port',8069)
199 if host == '' or None:
202 if not config.get_misc('webdav','enable',True):
203 raise Exception("WebDAV is disabled, cannot continue")
204 user_pool = self.pool.get('res.users')
205 current_user = user_pool.browse(cr, uid, uid, context=context)
206 pref_obj = self.pool.get('user.preference')
207 pref_ids = pref_obj.browse(cr, uid ,context.get('rec_id',False), context=context)
208 #TODO write documentation
209 res['description'] = self.__doc['other']
211 pref_ids = pref_ids[0]
212 if pref_ids.device == 'iphone':
213 url = host + ':' + str(port) + '/'+ pref_ids.service + '/' + cr.dbname + '/'+'calendars/'
215 url = host + ':' + str(port) + '/'+ pref_ids.service + '/' + cr.dbname + '/'+'calendars/'+ 'users/'+ current_user.login + '/'+ pref_ids.collection.name+ '/'+ pref_ids.calendar.name
217 res['description'] = self.__doc.get(pref_ids.device , self.__doc['other'])
218 file = open(addons.get_module_resource('caldav','doc', 'caldav_doc.pdf'),'rb')
219 res['caldav_doc_file'] = base64.encodestring(file.read())
221 #res['doc_link'] = 'http://doc.openerp.com/'
222 res['url'] = prefix+url
225 def browse_caldav(self, cr, uid, ids, context):
231 class user_preference(osv.osv_memory):
233 _name = 'user.preference'
234 _description = 'User preference Form'
237 'collection' :fields.many2one('document.directory', "Calendar Collection", required=True, domain = [('calendar_collection', '=', True)]),
238 'calendar' :fields.many2one('basic.calendar', 'Calendar', required=True),
239 'service': fields.selection([('webdav','CalDAV')], "Services"),
240 'device' : fields.selection([('other', 'Other'), ('iphone', 'iPhone'), ('android', 'Android based device'),('thunderbird', 'Sunbird/Thunderbird'), ('evolution','Evolution')], "Software/Devices"),
243 def _get_default_calendar(self, cr, uid, context):
246 name = context.get('cal_name')
248 collection_obj = self.pool.get('basic.calendar')
249 ids = collection_obj.search(cr, uid, [('name', '=', name)])
253 def _get_default_collection(self, cr, uid, context):
254 collection_obj = self.pool.get('document.directory')
255 ids = collection_obj.search(cr, uid, [('name', '=', 'c')])
261 'collection' : _get_default_collection,
262 'calendar' : _get_default_calendar,
267 def open_window(self, cr, uid, ids, context=None):
268 obj_model = self.pool.get('ir.model.data')
269 model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','caldav_Browse')])
270 resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])
271 context.update({'rec_id': ids})
275 'res_model': 'caldav.browse',
276 'views': [(resource_id,'form')],
277 'type': 'ir.actions.act_window',