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.translate import _
26 _logger = logging.getLogger(__name__)
28 class calendar_collection(osv.osv):
29 _inherit = 'document.directory'
31 'calendar_collection' : fields.boolean('Calendar Collection'),
32 'calendar_ids': fields.one2many('basic.calendar', 'collection_id', 'Calendars'),
35 'calendar_collection' : False,
38 def _get_root_calendar_directory(self, cr, uid, context=None):
39 objid = self.pool.get('ir.model.data')
41 mid = objid._get_id(cr, uid, 'document', 'dir_calendars')
44 root_id = objid.read(cr, uid, mid, ['res_id'])['res_id']
45 root_cal_dir = self.browse(cr,uid, root_id, context=context)
46 return root_cal_dir.name
48 _logger.warning('Cannot set root directory for Calendars:', exc_info=True)
52 def get_node_class(self, cr, uid, ids, dbro=None, dynamic=False, context=None):
54 dbro = self.browse(cr, uid, ids, context=context)
56 if dbro.calendar_collection:
58 return caldav_node.node_calendar_res_col
60 return caldav_node.node_calendar_collection
62 return super(calendar_collection, self).\
63 get_node_class(cr, uid, ids, dbro=dbro,dynamic=dynamic,
66 def get_description(self, cr, uid, ids, context=None):
67 #TODO : return description of all calendars
70 def get_schedule_inbox_URL(self, cr, uid, ids, context=None):
71 calendar_obj = self.pool.get('basic.calendar')
73 calendar_ids = calendar_obj.search(cr, uid, [
74 ('user_id', '=', uid), ('collection_id', 'in', ids)
75 ], limit=1, context=context)
77 root_cal_dir = self._get_root_calendar_directory(cr, uid, context=context)
80 calendar_id = calendar_ids[0]
81 calendar = calendar_obj.browse(cr, uid, calendar_id,
83 return '%s/%s' %(root_cal_dir, calendar.name)
85 def get_schedule_outbox_URL(self, cr, uid, ids, context=None):
86 return self.get_schedule_inbox_URL(cr, uid, ids, context=context)
90 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: