fix
[odoo/odoo.git] / addons / project_long_term / wizard / project_compute_tasks.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from osv import osv, fields
23
24 class project_compute_tasks(osv.osv_memory):
25     _name = 'project.compute.tasks'
26     _description = 'Project Compute Tasks'
27     _columns = {
28         'project_id': fields.many2one('project.project', 'Project', required=True)
29     }
30
31     def compute_date(self, cr, uid, ids, context=None):
32         """
33         Schedule the tasks according to users and priority.
34         """
35         project_pool = self.pool.get('project.project')
36         task_pool = self.pool.get('project.task')
37         if context is None:
38             context = {}
39         context['compute_by'] = 'project'
40         data = self.read(cr, uid, ids, [])[0]
41         project_id = data['project_id'][0]
42         project_pool.schedule_tasks(cr, uid, [project_id], context=context)
43         return self._open_task_list(cr, uid, data, context=context)
44
45     def _open_task_list(self, cr, uid, data, context=None):
46         """
47         Return the scheduled task list.
48         """
49         if context is None:
50             context = {}
51         mod_obj = self.pool.get('ir.model.data')
52         act_obj = self.pool.get('ir.actions.act_window')
53         result = mod_obj._get_id(cr, uid, 'project_long_term', 'act_resouce_allocation')
54         id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
55         result = {}
56         if not id:
57             return result
58         result = act_obj.read(cr, uid, [id], context=context)[0]
59         result['target'] = 'current'
60         return result
61
62 project_compute_tasks()
63
64 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: