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 fields, osv
23 from caldav import caldav
25 class project_task(osv.osv):
26 _name = "project.task"
27 _inherit = ["calendar.todo", "project.task"]
29 'attendee_ids': fields.many2many('calendar.attendee', \
30 'task_attendee_rel', 'task_id', 'attendee_id', 'Attendees'),
32 def import_cal(self, cr, uid, data, data_id=None, context={}):
33 todo_obj = self.pool.get('basic.calendar.todo')
34 vals = todo_obj.import_cal(cr, uid, data, context=context)
35 return self.check_import(cr, uid, vals, context=context)
37 def check_import(self, cr, uid, vals, context={}):
40 obj_tm = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.project_time_mode_id
41 if not val.has_key('planned_hours'):
42 # 'Computes duration' in days
44 if val.get('date') and val.get('date_deadline'):
45 start = datetime.strptime(val['date'], '%Y-%m-%d %H:%M:%S')
46 end = datetime.strptime(val['date_deadline'], '%Y-%m-%d %H:%M:%S')
48 plan = (diff.seconds/float(86400) + diff.days) * obj_tm.factor
49 val['planned_hours'] = plan
51 # Converts timedelta into hours
52 hours = (val['planned_hours'].seconds / float(3600)) + \
53 (val['planned_hours'].days * 24)
54 val['planned_hours'] = hours
55 exists, r_id = caldav.uid2openobjectid(cr, val['id'], self._name, val.get('recurrent_id'))
58 self.write(cr, uid, [exists], val)
61 task_id = self.create(cr, uid, val)
65 def export_cal(self, cr, uid, ids, context={}):
66 task_datas = self.read(cr, uid, ids, [], context ={'read': True})
68 for task in task_datas:
69 if task.get('planned_hours', None) and task.get('date_deadline', None):
70 task.pop('planned_hours')
72 todo_obj = self.pool.get('basic.calendar.todo')
73 ical = todo_obj.export_cal(cr, uid, tasks, context={'model': self._name})
74 calendar_val = ical.serialize()
75 calendar_val = calendar_val.replace('"', '').strip()
81 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: