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
25 from tools.translate import _
26 from base_calendar import base_calendar
27 from project.project import task as base_project_task
29 class project_task(osv.osv):
30 _name = "project.task"
31 _inherit = ["calendar.todo", "project.task"]
33 # force inherit from project.project_task so that
34 # calendar.todo.active is masked oute
35 'active': base_project_task._columns['active'],
36 'date_deadline': base_project_task._columns['date_deadline'],
37 'write_date': fields.datetime('Write Date'),
38 'create_date': fields.datetime('Create Date', readonly=True),
39 'attendee_ids': fields.many2many('calendar.attendee', \
40 'task_attendee_rel', 'task_id', 'attendee_id', 'Attendees'),
41 'state': fields.selection([('draft', 'Draft'),('open', 'In Progress'),('pending', 'Pending'), ('cancelled', 'Cancelled'), ('done', 'Done')], 'State', readonly=True, required=True,
42 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.\
43 \n If the task is over, the states is set to \'Done\'.'),
50 def open_task(self, cr, uid, ids, context=None):
52 Open Task Form for Project Task.
53 @param cr: the current row, from the database cursor,
54 @param uid: the current user’s ID for security checks,
55 @param ids: List of project task’s IDs
56 @param context: A standard dictionary for contextual values
57 @return: Dictionary value which open Project Task form.
60 data_pool = self.pool.get('ir.model.data')
62 task_form_id = data_pool.get_object(cr, uid, 'project', 'view_task_form2')
63 task_tree_id = data_pool.get_object(cr, uid, 'project', 'view_task_tree2')
64 task_calendar_id = data_pool.get_object(cr, uid, 'project', 'view_task_calendar')
69 'view_mode': 'form,tree',
70 'res_model': 'project.task',
72 'views': [(task_form_id, 'form'), (task_tree_id, 'tree'), (task_calendar_id, 'calendar')],
73 'type': 'ir.actions.act_window',
74 'res_id': base_calendar.base_calendar_id2real_id(id),
81 def import_cal(self, cr, uid, data, data_id=None, context=None):
82 todo_obj = self.pool.get('basic.calendar.todo')
83 vals = todo_obj.import_cal(cr, uid, data, context=context)
84 return self.check_import(cr, uid, vals, context=context)
86 def check_import(self, cr, uid, vals, context=None):
91 obj_tm = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.project_time_mode_id
92 if not val.get('planned_hours', False):
93 # 'Computes duration' in days
95 if val.get('date') and val.get('date_deadline'):
96 start = datetime.strptime(val['date'], '%Y-%m-%d %H:%M:%S')
97 end = datetime.strptime(val['date_deadline'], '%Y-%m-%d %H:%M:%S')
99 plan = (diff.seconds/float(86400) + diff.days) * obj_tm.factor
100 val['planned_hours'] = plan
102 # Converts timedelta into hours
103 hours = (val['planned_hours'].seconds / float(3600)) + \
104 (val['planned_hours'].days * 24)
105 val['planned_hours'] = hours
106 exists, r_id = calendar.uid2openobjectid(cr, val['id'], self._name, val.get('recurrent_id'))
109 self.write(cr, uid, [exists], val)
112 #set user_id with id, needed later
113 val.update({'user_id' : uid})
114 task_id = self.create(cr, uid, val)
118 def export_cal(self, cr, uid, ids, context=None):
121 task_datas = self.read(cr, uid, ids, [], context ={'read': True})
123 for task in task_datas:
124 if task.get('planned_hours', None) and task.get('date_deadline', None):
125 task.pop('planned_hours')
127 todo_obj = self.pool.get('basic.calendar.todo')
128 ical = todo_obj.export_cal(cr, uid, tasks, context={'model': self._name})
129 calendar_val = ical.serialize()
130 return calendar_val.replace('"', '').strip()
134 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: