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 calendar
24 from datetime import datetime
26 from project.project import task as base_project_task
28 class project_task(osv.osv):
29 _name = "project.task"
30 _inherit = ["calendar.todo", "project.task"]
32 # force inherit from project.project_task so that
33 # calendar.todo.active is masked oute
34 'active': base_project_task._columns['active'],
35 'write_date': fields.datetime('Write Date'),
36 'create_date': fields.datetime('Create Date', readonly=True),
37 'attendee_ids': fields.many2many('calendar.attendee', \
38 'task_attendee_rel', 'task_id', 'attendee_id', 'Attendees'),
39 'state': fields.selection([('draft', 'Draft'),('open', 'In Progress'),('pending', 'Pending'), ('cancelled', 'Cancelled'), ('done', 'Done')], 'State', readonly=True, required=True,
40 help='If the task is created the state is \'Draft\'.\n If the task is started, the state becomes \'In Progress\'.\n If review is needed the task is in \'Pending\' state.\
41 \n If the task is over, the states is set to \'Done\'.'),
47 def import_cal(self, cr, uid, data, data_id=None, context=None):
48 todo_obj = self.pool.get('basic.calendar.todo')
49 vals = todo_obj.import_cal(cr, uid, data, context=context)
50 return self.check_import(cr, uid, vals, context=context)
52 def check_import(self, cr, uid, vals, context=None):
57 obj_tm = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.project_time_mode_id
58 if not val.get('planned_hours', False):
59 # 'Computes duration' in days
61 if val.get('date') and val.get('date_deadline'):
62 start = datetime.strptime(val['date'], '%Y-%m-%d %H:%M:%S')
63 end = datetime.strptime(val['date_deadline'], '%Y-%m-%d %H:%M:%S')
65 plan = (diff.seconds/float(86400) + diff.days) * obj_tm.factor
66 val['planned_hours'] = plan
68 # Converts timedelta into hours
69 hours = (val['planned_hours'].seconds / float(3600)) + \
70 (val['planned_hours'].days * 24)
71 val['planned_hours'] = hours
72 exists, r_id = calendar.uid2openobjectid(cr, val['id'], self._name, val.get('recurrent_id'))
75 self.write(cr, uid, [exists], val)
78 task_id = self.create(cr, uid, val)
82 def export_cal(self, cr, uid, ids, context=None):
85 task_datas = self.read(cr, uid, ids, [], context ={'read': True})
87 for task in task_datas:
88 if task.get('planned_hours', None) and task.get('date_deadline', None):
89 task.pop('planned_hours')
91 todo_obj = self.pool.get('basic.calendar.todo')
92 ical = todo_obj.export_cal(cr, uid, tasks, context={'model': self._name})
93 calendar_val = ical.serialize()
94 return calendar_val.replace('"', '').strip()
98 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: